{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "655c3f50",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style>.container { width:100% !important; }</style>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from IPython.core.display import display, HTML\n",
    "display(HTML(\"<style>.container { width:100% !important; }</style>\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "favorite-magnet",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:08.217555Z",
     "iopub.status.busy": "2021-04-25T10:51:08.216667Z",
     "iopub.status.idle": "2021-04-25T10:51:08.221326Z",
     "shell.execute_reply": "2021-04-25T10:51:08.220639Z"
    },
    "id": "IU3QDXWZj56H",
    "papermill": {
     "duration": 0.072901,
     "end_time": "2021-04-25T10:51:08.221502",
     "exception": false,
     "start_time": "2021-04-25T10:51:08.148601",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "TEST = False\n",
    "\n",
    "Phase_1 = False\n",
    "Phase_2 = False\n",
    "Phase_3 = False\n",
    "Phase_4 = False\n",
    "\n",
    "DATA_FILE = \"sc2021_train_deals.csv\"\n",
    "NAME_OUTPUT_FILE = 'A_XGBM-tuning(v49)'\n",
    "NAME_OUTPUT_FOR_STAKING = 'XGBM_probs_for_staking(v49).npy'\n",
    "NAME_OUTPUT_FOR_STAKING_TEST = 'XGBM_probs-test_for_staking(v49).npy'\n",
    "TARGET = \"target\"\n",
    "\n",
    "\n",
    "# Range of values for selection in phase 1 :\n",
    "import numpy as np\n",
    "N_ESTIMATORS_RANG = list(range(10,500,1))#  [50000] #[5000] #[500] #\n",
    "RANG_LEARNING_RATE =   list(np.arange(0.01,0.1,0.005)) # 0.0015 #list(np.arange(5e-3,1e-1,5e-3)) # [0.005]\n",
    "\n",
    "N_TRIALS = 50\n",
    "\n",
    "SEED = 82736\n",
    "\n",
    "SELECT_PRED = False\n",
    "SELECT_PRED2 = False\n",
    "\n",
    "HIGH_PARAM_END = False\n",
    "\n",
    "# ------------------------------------------------------------------------------\n",
    "# Path definition\n",
    "# ------------------------------------------------------------------------------\n",
    "#from pathlib import Path\n",
    "import pathlib\n",
    "#input_path = Path('Data')\n",
    "DATA_DIR = pathlib.Path(\".\")\n",
    "\n",
    "AGG_COLS = [\"material_code\", \"company_code\", \"country\", \"region\", \"manager_code\"]\n",
    "CAT_COLS = [\"material_code\", \"company_code\", \"country\", \"region\", \"manager_code\", \"month\"]\n",
    "\n",
    "LOG_PATH = pathlib.Path(\"./log/\")\n",
    "NAME_RUN_LOG = 'Run__Logs.log'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "sharing-stupid",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:08.450179Z",
     "iopub.status.busy": "2021-04-25T10:51:08.449432Z",
     "iopub.status.idle": "2021-04-25T10:51:08.452285Z",
     "shell.execute_reply": "2021-04-25T10:51:08.452818Z"
    },
    "papermill": {
     "duration": 0.060715,
     "end_time": "2021-04-25T10:51:08.453016",
     "exception": false,
     "start_time": "2021-04-25T10:51:08.392301",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Берем полученные наилучшие значения гиперпараметров\n",
    "# xgb.XGBRegressor() с прошлых итераций\n",
    "params = {\n",
    "         'n_estimators': 330,\n",
    "         'learning_rate': 0.055, \n",
    "        'random_state': SEED,\n",
    "        'max_depth': 4, #3, \n",
    "        'min_child_weight': 115, #30, \n",
    "        'colsample_bytree': 0.7359281520613952, \n",
    "        'subsample': 0.3350726311191104, \n",
    "        'lambda': 0.07017450086376546, \n",
    "        'alpha': 0.06778367298243107,\n",
    "        'gamma': 0.30129207712879835\n",
    "        }\n",
    "#Наилучшие значения гиперпараметров: {'ml__colsample_bytree': 0.7359281520613952, 'ml__subsample': 0.3350726311191104}\n",
    "#Наилучшее значение AUC: -0.626\n",
    "#Наилучшие значения гиперпараметров: {'ml__lambda': 0.07017450086376546, 'ml__alpha': 0.06778367298243107, 'ml__gamma': 0.30129207712879835}\n",
    "#Наилучшее значение AUC: -0.625"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "vulnerable-newsletter",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:08.887787Z",
     "iopub.status.busy": "2021-04-25T10:51:08.877511Z",
     "iopub.status.idle": "2021-04-25T10:51:08.903876Z",
     "shell.execute_reply": "2021-04-25T10:51:08.904465Z"
    },
    "id": "otxlKdSTj56b",
    "outputId": "aa5ed5fe-410d-4872-bdd8-9197c83d5a2a",
    "papermill": {
     "duration": 0.092921,
     "end_time": "2021-04-25T10:51:08.904672",
     "exception": false,
     "start_time": "2021-04-25T10:51:08.811751",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Время старта скрипта: 17-12-2021 19:22\n"
     ]
    }
   ],
   "source": [
    "from time import time\n",
    "import datetime\n",
    "start_time = time()\n",
    "\n",
    "\n",
    "    \n",
    "LOG_PATH.mkdir(parents=True, exist_ok=True)\n",
    "\n",
    "with open(NAME_RUN_LOG, 'at', encoding='utf-8') as logfile:\n",
    "    print('\\n\\n***********************\\n***********************', \n",
    "          file=logfile)\n",
    "    print('Время старта скрипта: {}'.format(datetime.datetime.now().strftime(\"%d-%m-%Y %H:%M\")), \n",
    "          file=logfile)\n",
    "print('Время старта скрипта: {}'.format(datetime.datetime.now().strftime(\"%d-%m-%Y %H:%M\")))\n",
    "    \n",
    "#params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "70422200",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:09.018424Z",
     "iopub.status.busy": "2021-04-25T10:51:09.017718Z",
     "iopub.status.idle": "2021-04-25T10:51:28.067037Z",
     "shell.execute_reply": "2021-04-25T10:51:28.066269Z"
    },
    "papermill": {
     "duration": 19.107813,
     "end_time": "2021-04-25T10:51:28.067283",
     "exception": false,
     "start_time": "2021-04-25T10:51:08.959470",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "%matplotlib inline\n",
    "import matplotlib.pyplot as plt\n",
    "import pathlib\n",
    "import pandas as pd\n",
    "from catboost import CatBoostRegressor\n",
    "from sklearn.metrics import mean_squared_log_error, make_scorer\n",
    "\n",
    "import numpy as np\n",
    "# импортируем классы KFold, TimeSeriesSplit и GroupKFold,\n",
    "# реализующие стратегии перекрестной проверки, и\n",
    "# класс GridSearchCV для поиска гиперпараметров\n",
    "from sklearn.model_selection import (\n",
    "    KFold,\n",
    "    TimeSeriesSplit, \n",
    "    GroupKFold,\n",
    "    GridSearchCV\n",
    ")\n",
    "from tqdm.notebook import tqdm\n",
    "from datetime import datetime\n",
    "import lightgbm as lgb\n",
    "from sklearn.preprocessing import OrdinalEncoder\n",
    "from sklearn.preprocessing import OneHotEncoder\n",
    "from category_encoders import TargetEncoder, OrdinalEncoder, LeaveOneOutEncoder, CatBoostEncoder\n",
    "import warnings\n",
    "import xgboost as xgb\n",
    "from sklearn.ensemble import RandomForestRegressor, StackingRegressor, GradientBoostingRegressor\n",
    "import dill\n",
    "\n",
    "warnings.simplefilter(action='ignore', category=FutureWarning)\n",
    "# увеличиваем количество отображаемых столбцов\n",
    "pd.set_option('display.max_columns', 50)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4ef6b9d8",
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install -U scikit-learn --user"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "54983d03",
   "metadata": {},
   "outputs": [],
   "source": [
    "!conda activate sibur"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "c41b912f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.0.1\n"
     ]
    }
   ],
   "source": [
    "import sklearn\n",
    "print (sklearn.__version__)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "2a79ee68",
   "metadata": {},
   "outputs": [],
   "source": [
    "#!pip install optuna"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "7a92c451",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.compose import ColumnTransformer\n",
    "from sklearn.model_selection import GridSearchCV,RandomizedSearchCV\n",
    "import optuna\n",
    "from optuna.samplers import RandomSampler\n",
    "from optuna.integration import OptunaSearchCV\n",
    "from optuna.distributions import IntUniformDistribution, UniformDistribution\n",
    "from sklearn.model_selection import cross_val_predict"
   ]
  },
  {
   "cell_type": "raw",
   "id": "63a4e998",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:28.227866Z",
     "iopub.status.busy": "2021-04-25T10:51:28.226623Z",
     "iopub.status.idle": "2021-04-25T10:51:34.621408Z",
     "shell.execute_reply": "2021-04-25T10:51:34.620372Z"
    },
    "id": "lYBoXTJxj56d",
    "outputId": "1946ec14-3d81-402b-b068-45a01c44e368",
    "papermill": {
     "duration": 6.478111,
     "end_time": "2021-04-25T10:51:34.621574",
     "exception": false,
     "start_time": "2021-04-25T10:51:28.143463",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# загружаем необходимые библиотеки\n",
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.impute import SimpleImputer\n",
    "from sklearn.preprocessing import OneHotEncoder\n",
    "from sklearn.compose import ColumnTransformer\n",
    "from sklearn.pipeline import Pipeline\n",
    "from sklearn.model_selection import GridSearchCV,RandomizedSearchCV\n",
    "from sklearn.preprocessing import OrdinalEncoder\n",
    "# импортируем функцию roc_auc_score() для вычисления AUC-ROC\n",
    "import optuna\n",
    "from optuna.samplers import RandomSampler\n",
    "from optuna.integration import OptunaSearchCV\n",
    "from optuna.distributions import IntUniformDistribution, UniformDistribution\n",
    "# импортируем класс StandardScaler, позволяющий\n",
    "# выполнить стандартизацию\n",
    "from sklearn.preprocessing import StandardScaler, LabelEncoder\n",
    "from category_encoders import TargetEncoder, OrdinalEncoder, LeaveOneOutEncoder, CatBoostEncoder\n",
    "import xgboost as xgb\n",
    "\n",
    "from sklearn.metrics import roc_auc_score, roc_curve \n",
    "from sklearn.model_selection import cross_val_predict\n",
    "import scikitplot as skplt\n",
    "#import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "million-riding",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:34.768915Z",
     "iopub.status.busy": "2021-04-25T10:51:34.768275Z",
     "iopub.status.idle": "2021-04-25T10:51:35.141361Z",
     "shell.execute_reply": "2021-04-25T10:51:35.142208Z"
    },
    "id": "_CJf3w1Rj56e",
    "outputId": "c33766b2-a179-4a95-ea16-da37f6ef1116",
    "papermill": {
     "duration": 0.451849,
     "end_time": "2021-04-25T10:51:35.142399",
     "exception": false,
     "start_time": "2021-04-25T10:51:34.690550",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# увеличиваем количество выводимых столбцов\n",
    "pd.set_option('display.max_columns', 60)\n",
    "# загружаем набор\n",
    "data = pd.read_csv(DATA_DIR.joinpath(DATA_FILE), parse_dates=[\"month\", \"date\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "72b6c888",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>month</th>\n",
       "      <th>2018-01-01</th>\n",
       "      <th>2018-02-01</th>\n",
       "      <th>2018-03-01</th>\n",
       "      <th>2018-04-01</th>\n",
       "      <th>2018-05-01</th>\n",
       "      <th>2018-06-01</th>\n",
       "      <th>2018-07-01</th>\n",
       "      <th>2018-08-01</th>\n",
       "      <th>2018-09-01</th>\n",
       "      <th>2018-10-01</th>\n",
       "      <th>2018-11-01</th>\n",
       "      <th>2018-12-01</th>\n",
       "      <th>2019-01-01</th>\n",
       "      <th>2019-02-01</th>\n",
       "      <th>2019-03-01</th>\n",
       "      <th>2019-04-01</th>\n",
       "      <th>2019-05-01</th>\n",
       "      <th>2019-06-01</th>\n",
       "      <th>2019-07-01</th>\n",
       "      <th>2019-08-01</th>\n",
       "      <th>2019-09-01</th>\n",
       "      <th>2019-10-01</th>\n",
       "      <th>2019-11-01</th>\n",
       "      <th>2019-12-01</th>\n",
       "      <th>2020-01-01</th>\n",
       "      <th>2020-02-01</th>\n",
       "      <th>2020-03-01</th>\n",
       "      <th>2020-04-01</th>\n",
       "      <th>2020-05-01</th>\n",
       "      <th>2020-06-01</th>\n",
       "      <th>2020-07-01</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>124</th>\n",
       "      <th>7278</th>\n",
       "      <th>Россия</th>\n",
       "      <th>Респ. Татарстан</th>\n",
       "      <th>17460</th>\n",
       "      <td>340.0</td>\n",
       "      <td>340.0</td>\n",
       "      <td>260.0</td>\n",
       "      <td>240.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>185.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">133</th>\n",
       "      <th rowspan=\"4\" valign=\"top\">0</th>\n",
       "      <th rowspan=\"3\" valign=\"top\">Белоруссия</th>\n",
       "      <th>Минская обл.</th>\n",
       "      <th>10942</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>181.0</td>\n",
       "      <td>208.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>394.0</td>\n",
       "      <td>288.0</td>\n",
       "      <td>210.0</td>\n",
       "      <td>249.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Могилевская обл.</th>\n",
       "      <th>10942</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>166.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>г. Минск</th>\n",
       "      <th>10942</th>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>99.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Казахстан</th>\n",
       "      <th>г. Нур-Султан</th>\n",
       "      <th>13301</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>986</th>\n",
       "      <th>9943</th>\n",
       "      <th>Россия</th>\n",
       "      <th>Смоленская обл.</th>\n",
       "      <th>17460</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>83.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th rowspan=\"4\" valign=\"top\">998</th>\n",
       "      <th>0</th>\n",
       "      <th>Россия</th>\n",
       "      <th>Ленинградская обл.</th>\n",
       "      <th>18079</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3380</th>\n",
       "      <th>Россия</th>\n",
       "      <th>Ленинградская обл.</th>\n",
       "      <th>14956</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5410</th>\n",
       "      <th>Россия</th>\n",
       "      <th>г. Санкт-Петербург</th>\n",
       "      <th>14956</th>\n",
       "      <td>60.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6346</th>\n",
       "      <th>Россия</th>\n",
       "      <th>Респ. Башкортостан</th>\n",
       "      <th>10737</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 31 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "month                                                                  2018-01-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              340.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               60.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-02-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              340.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               20.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               60.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-03-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              260.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               30.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-04-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              240.0   \n",
       "133           0            Белоруссия Минская обл.       10942              200.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               30.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               60.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-05-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              220.0   \n",
       "133           0            Белоруссия Минская обл.       10942               60.0   \n",
       "                                      Могилевская обл.   10942              140.0   \n",
       "                                      г. Минск           10942               40.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               60.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-06-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              220.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942              160.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               80.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-07-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              220.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942              180.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               80.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-08-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              220.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               99.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               20.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                4.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-09-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              220.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942              100.0   \n",
       "                                      г. Минск           10942               60.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               80.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-10-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              280.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942              220.0   \n",
       "                                      г. Минск           10942              400.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               30.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               80.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-11-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              280.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942               20.0   \n",
       "                                      г. Минск           10942              120.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               80.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2018-12-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              280.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               20.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2019-01-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              200.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               40.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              120.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2019-02-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              200.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942               80.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               50.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956                0.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              119.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2019-03-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              200.0   \n",
       "133           0            Белоруссия Минская обл.       10942                0.0   \n",
       "                                      Могилевская обл.   10942              142.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               80.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              160.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               20.0   \n",
       "\n",
       "month                                                                  2019-04-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              185.0   \n",
       "133           0            Белоруссия Минская обл.       10942               36.0   \n",
       "                                      Могилевская обл.   10942              103.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                8.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               94.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              120.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2019-05-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460              103.0   \n",
       "133           0            Белоруссия Минская обл.       10942               98.0   \n",
       "                                      Могилевская обл.   10942              145.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              127.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              140.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               20.0   \n",
       "\n",
       "month                                                                  2019-06-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460               62.0   \n",
       "133           0            Белоруссия Минская обл.       10942               82.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079               10.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              121.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2019-07-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942               62.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              121.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              120.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               20.0   \n",
       "\n",
       "month                                                                  2019-08-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              145.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               41.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              129.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              120.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2019-09-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              124.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               83.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079               10.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              117.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               80.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               20.0   \n",
       "\n",
       "month                                                                  2019-10-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              181.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               82.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               45.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079               10.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              115.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              120.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               40.0   \n",
       "\n",
       "month                                                                  2019-11-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              208.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942               42.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               50.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              102.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              140.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               40.0   \n",
       "\n",
       "month                                                                  2019-12-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              207.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               45.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                6.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               29.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               40.0   \n",
       "\n",
       "month                                                                  2020-01-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942               17.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460                0.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               73.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               40.0   \n",
       "\n",
       "month                                                                  2020-02-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942               72.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               50.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460               21.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               74.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              180.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737                0.0   \n",
       "\n",
       "month                                                                  2020-03-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              250.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               40.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460               63.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                5.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              122.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              180.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               20.0   \n",
       "\n",
       "month                                                                  2020-04-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              394.0   \n",
       "                                      Могилевская обл.   10942              166.0   \n",
       "                                      г. Минск           10942               21.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460              125.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                0.0   \n",
       "              3380         Россия     Ленинградская обл. 14956              100.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              100.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               40.0   \n",
       "\n",
       "month                                                                  2020-05-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              288.0   \n",
       "                                      Могилевская обл.   10942               62.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460               84.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                3.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               15.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956              140.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               20.0   \n",
       "\n",
       "month                                                                  2020-06-01  \\\n",
       "material_code company_code country    region             manager_code               \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0   \n",
       "133           0            Белоруссия Минская обл.       10942              210.0   \n",
       "                                      Могилевская обл.   10942                0.0   \n",
       "                                      г. Минск           10942                0.0   \n",
       "                           Казахстан  г. Нур-Султан      13301               50.0   \n",
       "...                                                                           ...   \n",
       "986           9943         Россия     Смоленская обл.    17460               84.0   \n",
       "998           0            Россия     Ленинградская обл. 18079                3.0   \n",
       "              3380         Россия     Ленинградская обл. 14956               30.0   \n",
       "              5410         Россия     г. Санкт-Петербург 14956               40.0   \n",
       "              6346         Россия     Респ. Башкортостан 10737               21.0   \n",
       "\n",
       "month                                                                  2020-07-01  \n",
       "material_code company_code country    region             manager_code              \n",
       "124           7278         Россия     Респ. Татарстан    17460                0.0  \n",
       "133           0            Белоруссия Минская обл.       10942              249.0  \n",
       "                                      Могилевская обл.   10942                0.0  \n",
       "                                      г. Минск           10942                6.0  \n",
       "                           Казахстан  г. Нур-Султан      13301                0.0  \n",
       "...                                                                           ...  \n",
       "986           9943         Россия     Смоленская обл.    17460               83.0  \n",
       "998           0            Россия     Ленинградская обл. 18079                9.0  \n",
       "              3380         Россия     Ленинградская обл. 14956               50.0  \n",
       "              5410         Россия     г. Санкт-Петербург 14956                0.0  \n",
       "              6346         Россия     Респ. Башкортостан 10737               21.0  \n",
       "\n",
       "[941 rows x 31 columns]"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group_ts = data.groupby(AGG_COLS + [\"month\"])[\"volume\"].sum().unstack(fill_value=0)\n",
    "group_ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e846318a",
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_features_Cv(df: pd.DataFrame, month: pd.Timestamp, N=6, MDAD_1=2,  MNGR_GRP_MDAD=0) -> pd.DataFrame:\n",
    "    \"\"\"Calculate features for `month`.\"\"\"\n",
    "\n",
    "    start_period = month - pd.offsets.MonthBegin(N)\n",
    "    end_period = month - pd.offsets.MonthBegin(1)\n",
    "\n",
    "    df = df.loc[:, :end_period]\n",
    "\n",
    "    features = pd.DataFrame([], index=df.index)\n",
    "    features[\"month\"] = month.month\n",
    "    # формируем лаги за N месяцев\n",
    "    features[[f\"vol_tm{i}\" for i in range(N, 0, -1)]] = df.loc[:, start_period:end_period].copy()\n",
    "\n",
    "    ### !!!!!!!!!!!!!!   #################################################################################\n",
    "    rolling = df.rolling(12, axis=1, min_periods=1)\n",
    "    features = features.join(rolling.mean().iloc[:, -1].rename(\"last_year_avg\"))\n",
    "    \n",
    "    # Добавление ГРУППОВЫХ скользящих средних абсолютные отклонения(MDAD)\n",
    "    if MNGR_GRP_MDAD != 0:\n",
    "        period = MNGR_GRP_MDAD\n",
    "        df2 = df.copy()\n",
    "        df2[df2.columns.to_list()] = \\\n",
    "                                df2.groupby(level='manager_code').transform(lambda x: x.mean())\n",
    "        grp_manager_roll_mean = df2.rolling(period, axis=1, min_periods=1)\n",
    "        features = \\\n",
    "        features.join(grp_manager_roll_mean.apply(lambda x: np.nanmedian(np.abs(x - np.nanmedian(x))) , raw=True \n",
    "                        ).iloc[:, -1].rename(\"MNGR_GRP_MDAD\"+str(period))) \n",
    "    \n",
    "    if MDAD_1 != 0:\n",
    "        period = MDAD_1\n",
    "        rolling = df.rolling(period, axis=1, min_periods=1)\n",
    "        features = features.join( \n",
    "                        rolling.apply(lambda x: np.nanmedian(np.abs(x - np.nanmedian(x))) , raw=True \n",
    "                        ).iloc[:, -1].rename(\"mdad_\"+str(period)) )\n",
    "    '''\n",
    "    if MDAD_2 != 0 and MDAD_2 != MDAD_1:\n",
    "        period = MDAD_2\n",
    "        rolling = df.rolling(MDAD_2, axis=1, min_periods=1)\n",
    "        features = features.join( \n",
    "                        rolling.apply(lambda x: np.nanmedian(np.abs(x - np.nanmedian(x))) , raw=True \n",
    "                        ).iloc[:, -1].rename(\"mdad_\"+str(period)) )    \n",
    "                        \n",
    "    ### !!!!!!!!!!!!!!   ##################################################################################\n",
    "    # Cv1\n",
    "    \n",
    "    \n",
    "    \n",
    "    ##################################################################################################\n",
    "    '''\n",
    "    ##################################################################################################\n",
    "    ##################################################################################################\n",
    "\n",
    "    # выделяем КВАРТАЛЫ\n",
    "    #features[\"quarter\"] = month.quarter\n",
    "\n",
    "    return features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "e0bebd8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(DatetimeIndex(['2019-01-01', '2019-02-01', '2019-03-01', '2019-04-01',\n",
       "                '2019-05-01', '2019-06-01', '2019-07-01', '2019-08-01',\n",
       "                '2019-09-01', '2019-10-01', '2019-11-01', '2019-12-01',\n",
       "                '2020-01-01', '2020-02-01', '2020-03-01', '2020-04-01',\n",
       "                '2020-05-01', '2020-06-01', '2020-07-01'],\n",
       "               dtype='datetime64[ns]', freq='MS'),\n",
       " 19)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv_traine_range = pd.date_range(\"2019-01-01\", \"2020-07-01\", freq=\"MS\")\n",
    "\n",
    "#cv_traine_range = pd.date_range(\"2018-07-01\", \"2020-07-01\", freq=\"MS\")\n",
    "cv_traine_range, len(cv_traine_range)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "aabae3ca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "5bb611902d49442e9d613ea993d1d2bc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "  0%|          | 0/19 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['material_code', 'company_code', 'country', 'region', 'manager_code', 'month', 'vol_tm6', 'vol_tm5', 'vol_tm4', 'vol_tm3', 'vol_tm2', 'vol_tm1', 'last_year_avg', 'mdad_2']\n",
      "Wall time: 34.2 s\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "full_features2 = {}\n",
    "\n",
    "dataset_features2 = []\n",
    "for target_month in tqdm(cv_traine_range):\n",
    "#################################################################################################################################\n",
    "\n",
    "    features2 = get_features_Cv(group_ts, target_month, MDAD_1=2, MNGR_GRP_MDAD=0)\n",
    "\n",
    "#################################################################################################################################\n",
    "    features2[TARGET] = group_ts[target_month]\n",
    "    dataset_features2.append(features2.reset_index())\n",
    "full_features2 = pd.concat(dataset_features2, ignore_index=True)\n",
    "\n",
    "CAT_COLS = [\"material_code\", \"company_code\", \"country\", \"region\", \"manager_code\", \"month\"]\n",
    "# создаем список  переменных\n",
    "FTS_COLS = full_features2.columns.tolist()\n",
    "FTS_COLS.remove(TARGET)\n",
    "#################################################################################################################################\n",
    "print(FTS_COLS)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "b9962273",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 17879 entries, 0 to 17878\n",
      "Data columns (total 15 columns):\n",
      " #   Column         Non-Null Count  Dtype   \n",
      "---  ------         --------------  -----   \n",
      " 0   material_code  17879 non-null  int64   \n",
      " 1   company_code   17879 non-null  int64   \n",
      " 2   country        17879 non-null  category\n",
      " 3   region         17879 non-null  category\n",
      " 4   manager_code   17879 non-null  int64   \n",
      " 5   month          17879 non-null  int64   \n",
      " 6   vol_tm6        17879 non-null  float64 \n",
      " 7   vol_tm5        17879 non-null  float64 \n",
      " 8   vol_tm4        17879 non-null  float64 \n",
      " 9   vol_tm3        17879 non-null  float64 \n",
      " 10  vol_tm2        17879 non-null  float64 \n",
      " 11  vol_tm1        17879 non-null  float64 \n",
      " 12  last_year_avg  17879 non-null  float64 \n",
      " 13  mdad_2         17879 non-null  float64 \n",
      " 14  target         17879 non-null  float64 \n",
      "dtypes: category(2), float64(9), int64(4)\n",
      "memory usage: 1.8 MB\n"
     ]
    }
   ],
   "source": [
    "#cv_features = full_features2[:-941]\n",
    "cv_features = full_features2.copy() #[941:]\n",
    "\n",
    "for c in cv_features.columns:\n",
    "    col_type = cv_features[c].dtype\n",
    "    if col_type == 'object': # or col_type == 'int64': # or col_type.name == 'category':\n",
    "        cv_features[c] = cv_features[c].astype('category')\n",
    "\n",
    "cv_features.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1664fc1c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>1</td>\n",
       "      <td>220.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>260.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>1</td>\n",
       "      <td>180.0</td>\n",
       "      <td>99.0</td>\n",
       "      <td>60.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>91.583333</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>1</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>19.166667</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17874</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>31.416667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>83.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17875</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.750000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17876</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>85.583333</td>\n",
       "      <td>7.5</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17877</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>118.333333</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17878</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>7</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>25.083333</td>\n",
       "      <td>0.5</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>17879 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "0                124          7278      Россия     Респ. Татарстан   \n",
       "1                133             0  Белоруссия        Минская обл.   \n",
       "2                133             0  Белоруссия    Могилевская обл.   \n",
       "3                133             0  Белоруссия            г. Минск   \n",
       "4                133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "17874            986          9943      Россия     Смоленская обл.   \n",
       "17875            998             0      Россия  Ленинградская обл.   \n",
       "17876            998          3380      Россия  Ленинградская обл.   \n",
       "17877            998          5410      Россия  г. Санкт-Петербург   \n",
       "17878            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "0             17460      1    220.0    220.0    220.0    280.0    280.0   \n",
       "1             10942      1      0.0      0.0      0.0      0.0      0.0   \n",
       "2             10942      1      0.0      0.0    100.0    220.0     20.0   \n",
       "3             10942      1    180.0     99.0     60.0    400.0    120.0   \n",
       "4             13301      1     40.0     20.0     40.0     30.0      0.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "17874         17460      7      0.0     21.0     63.0    125.0     84.0   \n",
       "17875         18079      7      5.0      5.0      5.0      0.0      3.0   \n",
       "17876         14956      7     73.0     74.0    122.0    100.0     15.0   \n",
       "17877         14956      7    100.0    180.0    180.0    100.0    140.0   \n",
       "17878         10737      7     40.0      0.0     20.0     40.0     20.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "0        280.0     260.000000     0.0   200.0  \n",
       "1          0.0      21.666667     0.0     0.0  \n",
       "2          0.0      40.000000    10.0     0.0  \n",
       "3         20.0      91.583333    50.0    40.0  \n",
       "4         40.0      19.166667    20.0    40.0  \n",
       "...        ...            ...     ...     ...  \n",
       "17874     84.0      31.416667     0.0    83.0  \n",
       "17875      3.0       4.750000     0.0     9.0  \n",
       "17876     30.0      85.583333     7.5    50.0  \n",
       "17877     40.0     118.333333    50.0     0.0  \n",
       "17878     21.0      25.083333     0.5    21.0  \n",
       "\n",
       "[17879 rows x 15 columns]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cv_features"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "65bb3df7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 18 групп - блоки по 1 наблюдению(в 1 наблюдении данные 941 временного ряда)\n",
    "N_timeseries = 941 # в 1 наблюдении данные 941 временного ряда\n",
    "start_train = 1  # \n",
    "\n",
    "test_size=N_timeseries #*3\n",
    "#max_train_size = N_timeseries*6\n",
    "n_splits= 17 #int(len(full_features2)/(test_size))-1 - start_train # \n",
    "\n",
    "tscv = TimeSeriesSplit(n_splits=n_splits, \n",
    "                       #max_train_size=max_train_size, \n",
    "                       test_size=test_size)\n",
    "\n",
    "verbose =  False # True # "
   ]
  },
  {
   "cell_type": "raw",
   "id": "e853ce66",
   "metadata": {},
   "source": [
    "# 3 группы(типа как у организаторов)\n",
    "N_timeseries = 941\n",
    "start_train = 0  # \n",
    "\n",
    "test_size=N_timeseries*6\n",
    "max_train_size = N_timeseries*6\n",
    "n_splits= 2 #int(len(full_features2)/(test_size))-1 - start_train # \n",
    "\n",
    "tscv = TimeSeriesSplit(n_splits=n_splits, \n",
    "                       #max_train_size=max_train_size, \n",
    "                       test_size=test_size)\n",
    "\n",
    "verbose =  False # True # "
   ]
  },
  {
   "cell_type": "raw",
   "id": "9d586484",
   "metadata": {},
   "source": [
    "# 6 групп\n",
    "N_timeseries = 941\n",
    "start_train = 1  # \n",
    "\n",
    "test_size=N_timeseries *3\n",
    "#max_train_size = N_timeseries*6\n",
    "n_splits= 5 #int(len(full_features2)/(test_size))-1 - start_train # \n",
    "\n",
    "tscv = TimeSeriesSplit(n_splits=n_splits, \n",
    "                       #max_train_size=max_train_size, \n",
    "                       test_size=test_size)\n",
    "\n",
    "verbose =  False # True # "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "62561b6d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 1881\n",
      "TEST:  1882 ... 2822\n",
      "Обучающий набор: 2.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1882</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>3</td>\n",
       "      <td>220.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>236.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1883</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1884</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>3</td>\n",
       "      <td>100.0</td>\n",
       "      <td>220.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>46.666667</td>\n",
       "      <td>40.0</td>\n",
       "      <td>142.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1885</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>3</td>\n",
       "      <td>60.0</td>\n",
       "      <td>400.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.250000</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1886</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>3</td>\n",
       "      <td>40.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>26.666667</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2818</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2819</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>3</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2820</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2821</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>3</td>\n",
       "      <td>80.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>88.250000</td>\n",
       "      <td>0.5</td>\n",
       "      <td>160.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2822</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "1882            124          7278      Россия     Респ. Татарстан   \n",
       "1883            133             0  Белоруссия        Минская обл.   \n",
       "1884            133             0  Белоруссия    Могилевская обл.   \n",
       "1885            133             0  Белоруссия            г. Минск   \n",
       "1886            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "2818            986          9943      Россия     Смоленская обл.   \n",
       "2819            998             0      Россия  Ленинградская обл.   \n",
       "2820            998          3380      Россия  Ленинградская обл.   \n",
       "2821            998          5410      Россия  г. Санкт-Петербург   \n",
       "2822            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "1882         17460      3    220.0    280.0    280.0    280.0    200.0   \n",
       "1883         10942      3      0.0      0.0      0.0      0.0      0.0   \n",
       "1884         10942      3    100.0    220.0     20.0      0.0      0.0   \n",
       "1885         10942      3     60.0    400.0    120.0     20.0     40.0   \n",
       "1886         13301      3     40.0     30.0      0.0     40.0     40.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "2818         17460      3      0.0      0.0      0.0      0.0      0.0   \n",
       "2819         18079      3      5.0      5.0      0.0      0.0      5.0   \n",
       "2820         14956      3      0.0      0.0      0.0      0.0      0.0   \n",
       "2821         14956      3     80.0     80.0     80.0    100.0    120.0   \n",
       "2822         10737      3      0.0      0.0      0.0      0.0      0.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "1882    200.0     236.666667     0.0   200.0  \n",
       "1883      0.0      21.666667     0.0     0.0  \n",
       "1884     80.0      46.666667    40.0   142.0  \n",
       "1885      0.0      93.250000    20.0     0.0  \n",
       "1886     50.0      26.666667     5.0     0.0  \n",
       "...       ...            ...     ...     ...  \n",
       "2818      0.0       0.000000     0.0     0.0  \n",
       "2819      5.0       2.000000     0.0     0.0  \n",
       "2820      0.0       0.000000     0.0    80.0  \n",
       "2821    119.0      88.250000     0.5   160.0  \n",
       "2822      0.0       0.000000     0.0    20.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 2822\n",
      "TEST:  2823 ... 3763\n",
      "Обучающий набор: 3.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2823</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>4</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>231.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>185.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2824</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2825</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>4</td>\n",
       "      <td>220.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>58.500000</td>\n",
       "      <td>31.0</td>\n",
       "      <td>103.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2826</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>4</td>\n",
       "      <td>400.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.250000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2827</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>4</td>\n",
       "      <td>30.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.166667</td>\n",
       "      <td>25.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3759</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3760</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>4</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.5</td>\n",
       "      <td>8.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3761</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>6.666667</td>\n",
       "      <td>40.0</td>\n",
       "      <td>94.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3762</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>4</td>\n",
       "      <td>80.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>93.250000</td>\n",
       "      <td>20.5</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3763</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1.666667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "2823            124          7278      Россия     Респ. Татарстан   \n",
       "2824            133             0  Белоруссия        Минская обл.   \n",
       "2825            133             0  Белоруссия    Могилевская обл.   \n",
       "2826            133             0  Белоруссия            г. Минск   \n",
       "2827            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "3759            986          9943      Россия     Смоленская обл.   \n",
       "3760            998             0      Россия  Ленинградская обл.   \n",
       "3761            998          3380      Россия  Ленинградская обл.   \n",
       "3762            998          5410      Россия  г. Санкт-Петербург   \n",
       "3763            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "2823         17460      4    280.0    280.0    280.0    200.0    200.0   \n",
       "2824         10942      4      0.0      0.0      0.0      0.0      0.0   \n",
       "2825         10942      4    220.0     20.0      0.0      0.0     80.0   \n",
       "2826         10942      4    400.0    120.0     20.0     40.0      0.0   \n",
       "2827         13301      4     30.0      0.0     40.0     40.0     50.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "3759         17460      4      0.0      0.0      0.0      0.0      0.0   \n",
       "3760         18079      4      5.0      0.0      0.0      5.0      5.0   \n",
       "3761         14956      4      0.0      0.0      0.0      0.0      0.0   \n",
       "3762         14956      4     80.0     80.0    100.0    120.0    119.0   \n",
       "3763         10737      4      0.0      0.0      0.0      0.0      0.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "2823    200.0     231.666667     0.0   185.0  \n",
       "2824      0.0      21.666667     0.0    36.0  \n",
       "2825    142.0      58.500000    31.0   103.0  \n",
       "2826      0.0      93.250000     0.0     0.0  \n",
       "2827      0.0      24.166667    25.0    40.0  \n",
       "...       ...            ...     ...     ...  \n",
       "3759      0.0       0.000000     0.0     0.0  \n",
       "3760      0.0       2.000000     2.5     8.0  \n",
       "3761     80.0       6.666667    40.0    94.0  \n",
       "3762    160.0      93.250000    20.5   120.0  \n",
       "3763     20.0       1.666667    10.0     0.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 3763\n",
      "TEST:  3764 ... 4704\n",
      "Обучающий набор: 4.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>3764</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>5</td>\n",
       "      <td>280.0</td>\n",
       "      <td>280.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>185.0</td>\n",
       "      <td>227.083333</td>\n",
       "      <td>7.5</td>\n",
       "      <td>103.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3765</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>18.0</td>\n",
       "      <td>98.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3766</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>5</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>67.083333</td>\n",
       "      <td>19.5</td>\n",
       "      <td>145.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3767</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>5</td>\n",
       "      <td>120.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>93.250000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3768</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4700</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4701</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>2.666667</td>\n",
       "      <td>4.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4702</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>14.500000</td>\n",
       "      <td>7.0</td>\n",
       "      <td>127.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4703</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>5</td>\n",
       "      <td>80.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>98.250000</td>\n",
       "      <td>20.0</td>\n",
       "      <td>140.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4704</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.666667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "3764            124          7278      Россия     Респ. Татарстан   \n",
       "3765            133             0  Белоруссия        Минская обл.   \n",
       "3766            133             0  Белоруссия    Могилевская обл.   \n",
       "3767            133             0  Белоруссия            г. Минск   \n",
       "3768            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "4700            986          9943      Россия     Смоленская обл.   \n",
       "4701            998             0      Россия  Ленинградская обл.   \n",
       "4702            998          3380      Россия  Ленинградская обл.   \n",
       "4703            998          5410      Россия  г. Санкт-Петербург   \n",
       "4704            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "3764         17460      5    280.0    280.0    200.0    200.0    200.0   \n",
       "3765         10942      5      0.0      0.0      0.0      0.0      0.0   \n",
       "3766         10942      5     20.0      0.0      0.0     80.0    142.0   \n",
       "3767         10942      5    120.0     20.0     40.0      0.0      0.0   \n",
       "3768         13301      5      0.0     40.0     40.0     50.0      0.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "4700         17460      5      0.0      0.0      0.0      0.0      0.0   \n",
       "4701         18079      5      0.0      0.0      5.0      5.0      0.0   \n",
       "4702         14956      5      0.0      0.0      0.0      0.0     80.0   \n",
       "4703         14956      5     80.0    100.0    120.0    119.0    160.0   \n",
       "4704         10737      5      0.0      0.0      0.0      0.0     20.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "3764    185.0     227.083333     7.5   103.0  \n",
       "3765     36.0       8.000000    18.0    98.0  \n",
       "3766    103.0      67.083333    19.5   145.0  \n",
       "3767      0.0      93.250000     0.0     0.0  \n",
       "3768     40.0      25.000000    20.0     0.0  \n",
       "...       ...            ...     ...     ...  \n",
       "4700      0.0       0.000000     0.0     0.0  \n",
       "4701      8.0       2.666667     4.0     5.0  \n",
       "4702     94.0      14.500000     7.0   127.0  \n",
       "4703    120.0      98.250000    20.0   140.0  \n",
       "4704      0.0       1.666667    10.0    20.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 4704\n",
      "TEST:  4705 ... 5645\n",
      "Обучающий набор: 5.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4705</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>6</td>\n",
       "      <td>280.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>185.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>217.333333</td>\n",
       "      <td>41.0</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4706</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>11.166667</td>\n",
       "      <td>31.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4707</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4708</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>6</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>89.916667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4709</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>6</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>25.000000</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5641</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5642</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>3.083333</td>\n",
       "      <td>1.5</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5643</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>25.083333</td>\n",
       "      <td>16.5</td>\n",
       "      <td>121.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5644</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>6</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>104.916667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5645</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>3.333333</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "4705            124          7278      Россия     Респ. Татарстан   \n",
       "4706            133             0  Белоруссия        Минская обл.   \n",
       "4707            133             0  Белоруссия    Могилевская обл.   \n",
       "4708            133             0  Белоруссия            г. Минск   \n",
       "4709            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "5641            986          9943      Россия     Смоленская обл.   \n",
       "5642            998             0      Россия  Ленинградская обл.   \n",
       "5643            998          3380      Россия  Ленинградская обл.   \n",
       "5644            998          5410      Россия  г. Санкт-Петербург   \n",
       "5645            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "4705         17460      6    280.0    200.0    200.0    200.0    185.0   \n",
       "4706         10942      6      0.0      0.0      0.0      0.0     36.0   \n",
       "4707         10942      6      0.0      0.0     80.0    142.0    103.0   \n",
       "4708         10942      6     20.0     40.0      0.0      0.0      0.0   \n",
       "4709         13301      6     40.0     40.0     50.0      0.0     40.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "5641         17460      6      0.0      0.0      0.0      0.0      0.0   \n",
       "5642         18079      6      0.0      5.0      5.0      0.0      8.0   \n",
       "5643         14956      6      0.0      0.0      0.0     80.0     94.0   \n",
       "5644         14956      6    100.0    120.0    119.0    160.0    120.0   \n",
       "5645         10737      6      0.0      0.0      0.0     20.0      0.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "4705    103.0     217.333333    41.0    62.0  \n",
       "4706     98.0      11.166667    31.0    82.0  \n",
       "4707    145.0      67.500000    21.0     0.0  \n",
       "4708      0.0      89.916667     0.0     0.0  \n",
       "4709      0.0      25.000000    20.0    40.0  \n",
       "...       ...            ...     ...     ...  \n",
       "5641      0.0       0.000000     0.0     0.0  \n",
       "5642      5.0       3.083333     1.5    10.0  \n",
       "5643    127.0      25.083333    16.5   121.0  \n",
       "5644    140.0     104.916667    10.0   100.0  \n",
       "5645     20.0       3.333333    10.0     0.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 5645\n",
      "TEST:  5646 ... 6586\n",
      "Обучающий набор: 6.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>5646</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>185.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>204.166667</td>\n",
       "      <td>20.5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5647</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>18.000000</td>\n",
       "      <td>8.0</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5648</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>72.5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5649</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>76.583333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5650</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>7</td>\n",
       "      <td>40.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>28.333333</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6582</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6583</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>3.916667</td>\n",
       "      <td>2.5</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6584</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>35.166667</td>\n",
       "      <td>3.0</td>\n",
       "      <td>121.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6585</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>120.0</td>\n",
       "      <td>119.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>106.583333</td>\n",
       "      <td>20.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6586</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.333333</td>\n",
       "      <td>10.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "5646            124          7278      Россия     Респ. Татарстан   \n",
       "5647            133             0  Белоруссия        Минская обл.   \n",
       "5648            133             0  Белоруссия    Могилевская обл.   \n",
       "5649            133             0  Белоруссия            г. Минск   \n",
       "5650            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "6582            986          9943      Россия     Смоленская обл.   \n",
       "6583            998             0      Россия  Ленинградская обл.   \n",
       "6584            998          3380      Россия  Ленинградская обл.   \n",
       "6585            998          5410      Россия  г. Санкт-Петербург   \n",
       "6586            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "5646         17460      7    200.0    200.0    200.0    185.0    103.0   \n",
       "5647         10942      7      0.0      0.0      0.0     36.0     98.0   \n",
       "5648         10942      7      0.0     80.0    142.0    103.0    145.0   \n",
       "5649         10942      7     40.0      0.0      0.0      0.0      0.0   \n",
       "5650         13301      7     40.0     50.0      0.0     40.0      0.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "6582         17460      7      0.0      0.0      0.0      0.0      0.0   \n",
       "6583         18079      7      5.0      5.0      0.0      8.0      5.0   \n",
       "6584         14956      7      0.0      0.0     80.0     94.0    127.0   \n",
       "6585         14956      7    120.0    119.0    160.0    120.0    140.0   \n",
       "6586         10737      7      0.0      0.0     20.0      0.0     20.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "5646     62.0     204.166667    20.5     0.0  \n",
       "5647     82.0      18.000000     8.0    62.0  \n",
       "5648      0.0      67.500000    72.5     0.0  \n",
       "5649      0.0      76.583333     0.0     0.0  \n",
       "5650     40.0      28.333333    20.0    40.0  \n",
       "...       ...            ...     ...     ...  \n",
       "6582      0.0       0.000000     0.0     0.0  \n",
       "6583     10.0       3.916667     2.5     5.0  \n",
       "6584    121.0      35.166667     3.0   121.0  \n",
       "6585    100.0     106.583333    20.0   120.0  \n",
       "6586      0.0       3.333333    10.0    20.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 6586\n",
      "TEST:  6587 ... 7527\n",
      "Обучающий набор: 7.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6587</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>8</td>\n",
       "      <td>200.0</td>\n",
       "      <td>200.0</td>\n",
       "      <td>185.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>185.833333</td>\n",
       "      <td>31.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6588</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>23.166667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>145.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6589</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>8</td>\n",
       "      <td>80.0</td>\n",
       "      <td>142.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6590</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>61.583333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6591</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>8</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>28.333333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7523</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7524</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>8</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.333333</td>\n",
       "      <td>2.5</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7525</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>45.250000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>129.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7526</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>8</td>\n",
       "      <td>119.0</td>\n",
       "      <td>160.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>109.916667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7527</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>8</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "6587            124          7278      Россия     Респ. Татарстан   \n",
       "6588            133             0  Белоруссия        Минская обл.   \n",
       "6589            133             0  Белоруссия    Могилевская обл.   \n",
       "6590            133             0  Белоруссия            г. Минск   \n",
       "6591            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "7523            986          9943      Россия     Смоленская обл.   \n",
       "7524            998             0      Россия  Ленинградская обл.   \n",
       "7525            998          3380      Россия  Ленинградская обл.   \n",
       "7526            998          5410      Россия  г. Санкт-Петербург   \n",
       "7527            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "6587         17460      8    200.0    200.0    185.0    103.0     62.0   \n",
       "6588         10942      8      0.0      0.0     36.0     98.0     82.0   \n",
       "6589         10942      8     80.0    142.0    103.0    145.0      0.0   \n",
       "6590         10942      8      0.0      0.0      0.0      0.0      0.0   \n",
       "6591         13301      8     50.0      0.0     40.0      0.0     40.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "7523         17460      8      0.0      0.0      0.0      0.0      0.0   \n",
       "7524         18079      8      5.0      0.0      8.0      5.0     10.0   \n",
       "7525         14956      8      0.0     80.0     94.0    127.0    121.0   \n",
       "7526         14956      8    119.0    160.0    120.0    140.0    100.0   \n",
       "7527         10737      8      0.0     20.0      0.0     20.0      0.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "6587      0.0     185.833333    31.0     0.0  \n",
       "6588     62.0      23.166667    10.0   145.0  \n",
       "6589      0.0      67.500000     0.0     0.0  \n",
       "6590      0.0      61.583333     0.0    41.0  \n",
       "6591     40.0      28.333333     0.0    40.0  \n",
       "...       ...            ...     ...     ...  \n",
       "7523      0.0       0.000000     0.0     0.0  \n",
       "7524      5.0       4.333333     2.5     5.0  \n",
       "7525    121.0      45.250000     0.0   129.0  \n",
       "7526    120.0     109.916667    10.0   120.0  \n",
       "7527     20.0       5.000000    10.0     0.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 7527\n",
      "TEST:  7528 ... 8468\n",
      "Обучающий набор: 8.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7528</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>9</td>\n",
       "      <td>200.0</td>\n",
       "      <td>185.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>167.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7529</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>36.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>35.250000</td>\n",
       "      <td>41.5</td>\n",
       "      <td>124.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7530</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>9</td>\n",
       "      <td>142.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7531</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>56.750000</td>\n",
       "      <td>20.5</td>\n",
       "      <td>83.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7532</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8464</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8465</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>9</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>4.416667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8466</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>9</td>\n",
       "      <td>80.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>56.000000</td>\n",
       "      <td>4.0</td>\n",
       "      <td>117.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8467</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>9</td>\n",
       "      <td>160.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>111.583333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>80.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8468</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>9</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "7528            124          7278      Россия     Респ. Татарстан   \n",
       "7529            133             0  Белоруссия        Минская обл.   \n",
       "7530            133             0  Белоруссия    Могилевская обл.   \n",
       "7531            133             0  Белоруссия            г. Минск   \n",
       "7532            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "8464            986          9943      Россия     Смоленская обл.   \n",
       "8465            998             0      Россия  Ленинградская обл.   \n",
       "8466            998          3380      Россия  Ленинградская обл.   \n",
       "8467            998          5410      Россия  г. Санкт-Петербург   \n",
       "8468            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "7528         17460      9    200.0    185.0    103.0     62.0      0.0   \n",
       "7529         10942      9      0.0     36.0     98.0     82.0     62.0   \n",
       "7530         10942      9    142.0    103.0    145.0      0.0      0.0   \n",
       "7531         10942      9      0.0      0.0      0.0      0.0      0.0   \n",
       "7532         13301      9      0.0     40.0      0.0     40.0     40.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "8464         17460      9      0.0      0.0      0.0      0.0      0.0   \n",
       "8465         18079      9      0.0      8.0      5.0     10.0      5.0   \n",
       "8466         14956      9     80.0     94.0    127.0    121.0    121.0   \n",
       "8467         14956      9    160.0    120.0    140.0    100.0    120.0   \n",
       "8468         10737      9     20.0      0.0     20.0      0.0     20.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "7528      0.0     167.500000     0.0     0.0  \n",
       "7529    145.0      35.250000    41.5   124.0  \n",
       "7530      0.0      67.500000     0.0     0.0  \n",
       "7531     41.0      56.750000    20.5    83.0  \n",
       "7532     40.0      30.000000     0.0     0.0  \n",
       "...       ...            ...     ...     ...  \n",
       "8464      0.0       0.000000     0.0     0.0  \n",
       "8465      5.0       4.416667     0.0    10.0  \n",
       "8466    129.0      56.000000     4.0   117.0  \n",
       "8467    120.0     111.583333     0.0    80.0  \n",
       "8468      0.0       5.000000    10.0    20.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 8468\n",
      "TEST:  8469 ... 9409\n",
      "Обучающий набор: 9.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8469</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>10</td>\n",
       "      <td>185.0</td>\n",
       "      <td>103.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>149.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8470</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>10</td>\n",
       "      <td>36.0</td>\n",
       "      <td>98.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>45.583333</td>\n",
       "      <td>10.5</td>\n",
       "      <td>181.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8471</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>10</td>\n",
       "      <td>103.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>59.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8472</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>10</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>58.666667</td>\n",
       "      <td>21.0</td>\n",
       "      <td>82.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8473</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>10</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>26.666667</td>\n",
       "      <td>20.0</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9405</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>10</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9406</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>10</td>\n",
       "      <td>8.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>4.833333</td>\n",
       "      <td>2.5</td>\n",
       "      <td>10.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9407</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>10</td>\n",
       "      <td>94.0</td>\n",
       "      <td>127.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>65.750000</td>\n",
       "      <td>6.0</td>\n",
       "      <td>115.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9408</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>10</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>111.583333</td>\n",
       "      <td>20.0</td>\n",
       "      <td>120.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9409</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>10</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>6.666667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      material_code  company_code     country              region  \\\n",
       "8469            124          7278      Россия     Респ. Татарстан   \n",
       "8470            133             0  Белоруссия        Минская обл.   \n",
       "8471            133             0  Белоруссия    Могилевская обл.   \n",
       "8472            133             0  Белоруссия            г. Минск   \n",
       "8473            133             0   Казахстан       г. Нур-Султан   \n",
       "...             ...           ...         ...                 ...   \n",
       "9405            986          9943      Россия     Смоленская обл.   \n",
       "9406            998             0      Россия  Ленинградская обл.   \n",
       "9407            998          3380      Россия  Ленинградская обл.   \n",
       "9408            998          5410      Россия  г. Санкт-Петербург   \n",
       "9409            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "      manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "8469         17460     10    185.0    103.0     62.0      0.0      0.0   \n",
       "8470         10942     10     36.0     98.0     82.0     62.0    145.0   \n",
       "8471         10942     10    103.0    145.0      0.0      0.0      0.0   \n",
       "8472         10942     10      0.0      0.0      0.0      0.0     41.0   \n",
       "8473         13301     10     40.0      0.0     40.0     40.0     40.0   \n",
       "...            ...    ...      ...      ...      ...      ...      ...   \n",
       "9405         17460     10      0.0      0.0      0.0      0.0      0.0   \n",
       "9406         18079     10      8.0      5.0     10.0      5.0      5.0   \n",
       "9407         14956     10     94.0    127.0    121.0    121.0    129.0   \n",
       "9408         14956     10    120.0    140.0    100.0    120.0    120.0   \n",
       "9409         10737     10      0.0     20.0      0.0     20.0      0.0   \n",
       "\n",
       "      vol_tm1  last_year_avg  mdad_2  target  \n",
       "8469      0.0     149.166667     0.0     0.0  \n",
       "8470    124.0      45.583333    10.5   181.0  \n",
       "8471      0.0      59.166667     0.0     0.0  \n",
       "8472     83.0      58.666667    21.0    82.0  \n",
       "8473      0.0      26.666667    20.0    45.0  \n",
       "...       ...            ...     ...     ...  \n",
       "9405      0.0       0.000000     0.0     0.0  \n",
       "9406     10.0       4.833333     2.5    10.0  \n",
       "9407    117.0      65.750000     6.0   115.0  \n",
       "9408     80.0     111.583333    20.0   120.0  \n",
       "9409     20.0       6.666667    10.0    40.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 9409\n",
      "TEST:  9410 ... 10350\n",
      "Обучающий набор: 10.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9410</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>11</td>\n",
       "      <td>103.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>125.833333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9411</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>11</td>\n",
       "      <td>98.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>181.0</td>\n",
       "      <td>60.666667</td>\n",
       "      <td>28.5</td>\n",
       "      <td>208.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9412</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>11</td>\n",
       "      <td>145.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.833333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9413</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>11</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>32.166667</td>\n",
       "      <td>0.5</td>\n",
       "      <td>42.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9414</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>11</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>27.916667</td>\n",
       "      <td>22.5</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10346</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>11</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10347</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>11</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.250000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10348</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>11</td>\n",
       "      <td>127.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>75.333333</td>\n",
       "      <td>1.0</td>\n",
       "      <td>102.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10349</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>11</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>114.916667</td>\n",
       "      <td>20.0</td>\n",
       "      <td>140.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10350</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>11</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "9410             124          7278      Россия     Респ. Татарстан   \n",
       "9411             133             0  Белоруссия        Минская обл.   \n",
       "9412             133             0  Белоруссия    Могилевская обл.   \n",
       "9413             133             0  Белоруссия            г. Минск   \n",
       "9414             133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "10346            986          9943      Россия     Смоленская обл.   \n",
       "10347            998             0      Россия  Ленинградская обл.   \n",
       "10348            998          3380      Россия  Ленинградская обл.   \n",
       "10349            998          5410      Россия  г. Санкт-Петербург   \n",
       "10350            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "9410          17460     11    103.0     62.0      0.0      0.0      0.0   \n",
       "9411          10942     11     98.0     82.0     62.0    145.0    124.0   \n",
       "9412          10942     11    145.0      0.0      0.0      0.0      0.0   \n",
       "9413          10942     11      0.0      0.0      0.0     41.0     83.0   \n",
       "9414          13301     11      0.0     40.0     40.0     40.0      0.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "10346         17460     11      0.0      0.0      0.0      0.0      0.0   \n",
       "10347         18079     11      5.0     10.0      5.0      5.0     10.0   \n",
       "10348         14956     11    127.0    121.0    121.0    129.0    117.0   \n",
       "10349         14956     11    140.0    100.0    120.0    120.0     80.0   \n",
       "10350         10737     11     20.0      0.0     20.0      0.0     20.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "9410       0.0     125.833333     0.0     0.0  \n",
       "9411     181.0      60.666667    28.5   208.0  \n",
       "9412       0.0      40.833333     0.0     0.0  \n",
       "9413      82.0      32.166667     0.5    42.0  \n",
       "9414      45.0      27.916667    22.5    50.0  \n",
       "...        ...            ...     ...     ...  \n",
       "10346      0.0       0.000000     0.0     0.0  \n",
       "10347     10.0       5.250000     0.0     0.0  \n",
       "10348    115.0      75.333333     1.0   102.0  \n",
       "10349    120.0     114.916667    20.0   140.0  \n",
       "10350     40.0      10.000000    10.0    40.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 10350\n",
      "TEST:  10351 ... 11291\n",
      "Обучающий набор: 11.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10351</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>12</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>102.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10352</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>12</td>\n",
       "      <td>82.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>181.0</td>\n",
       "      <td>208.0</td>\n",
       "      <td>78.000000</td>\n",
       "      <td>13.5</td>\n",
       "      <td>207.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10353</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>12</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>39.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10354</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>12</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>25.666667</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10355</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>12</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>32.083333</td>\n",
       "      <td>2.5</td>\n",
       "      <td>45.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11287</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>12</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11288</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>12</td>\n",
       "      <td>10.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.250000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11289</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>12</td>\n",
       "      <td>121.0</td>\n",
       "      <td>121.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>83.833333</td>\n",
       "      <td>6.5</td>\n",
       "      <td>29.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11290</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>12</td>\n",
       "      <td>100.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>119.916667</td>\n",
       "      <td>10.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11291</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>12</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>13.333333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "10351            124          7278      Россия     Респ. Татарстан   \n",
       "10352            133             0  Белоруссия        Минская обл.   \n",
       "10353            133             0  Белоруссия    Могилевская обл.   \n",
       "10354            133             0  Белоруссия            г. Минск   \n",
       "10355            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "11287            986          9943      Россия     Смоленская обл.   \n",
       "11288            998             0      Россия  Ленинградская обл.   \n",
       "11289            998          3380      Россия  Ленинградская обл.   \n",
       "11290            998          5410      Россия  г. Санкт-Петербург   \n",
       "11291            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "10351         17460     12     62.0      0.0      0.0      0.0      0.0   \n",
       "10352         10942     12     82.0     62.0    145.0    124.0    181.0   \n",
       "10353         10942     12      0.0      0.0      0.0      0.0      0.0   \n",
       "10354         10942     12      0.0      0.0     41.0     83.0     82.0   \n",
       "10355         13301     12     40.0     40.0     40.0      0.0     45.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "11287         17460     12      0.0      0.0      0.0      0.0      0.0   \n",
       "11288         18079     12     10.0      5.0      5.0     10.0     10.0   \n",
       "11289         14956     12    121.0    121.0    129.0    117.0    115.0   \n",
       "11290         14956     12    100.0    120.0    120.0     80.0    120.0   \n",
       "11291         10737     12      0.0     20.0      0.0     20.0     40.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "10351      0.0     102.500000     0.0     0.0  \n",
       "10352    208.0      78.000000    13.5   207.0  \n",
       "10353      0.0      39.166667     0.0     0.0  \n",
       "10354     42.0      25.666667    20.0     0.0  \n",
       "10355     50.0      32.083333     2.5    45.0  \n",
       "...        ...            ...     ...     ...  \n",
       "11287      0.0       0.000000     0.0     0.0  \n",
       "11288      0.0       5.250000     5.0     6.0  \n",
       "11289    102.0      83.833333     6.5    29.0  \n",
       "11290    140.0     119.916667    10.0   100.0  \n",
       "11291     40.0      13.333333     0.0    40.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 11291\n",
      "TEST:  11292 ... 12232\n",
      "Обучающий набор: 12.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>11292</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>79.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11293</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>1</td>\n",
       "      <td>62.0</td>\n",
       "      <td>145.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>181.0</td>\n",
       "      <td>208.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>95.250000</td>\n",
       "      <td>0.5</td>\n",
       "      <td>17.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11294</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>39.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11295</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>41.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>24.000000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11296</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>1</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>32.500000</td>\n",
       "      <td>2.5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12228</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>1</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12229</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>1</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.750000</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12230</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>1</td>\n",
       "      <td>121.0</td>\n",
       "      <td>129.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>86.250000</td>\n",
       "      <td>36.5</td>\n",
       "      <td>73.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12231</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>1</td>\n",
       "      <td>120.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>119.916667</td>\n",
       "      <td>20.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12232</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>1</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>16.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "11292            124          7278      Россия     Респ. Татарстан   \n",
       "11293            133             0  Белоруссия        Минская обл.   \n",
       "11294            133             0  Белоруссия    Могилевская обл.   \n",
       "11295            133             0  Белоруссия            г. Минск   \n",
       "11296            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "12228            986          9943      Россия     Смоленская обл.   \n",
       "12229            998             0      Россия  Ленинградская обл.   \n",
       "12230            998          3380      Россия  Ленинградская обл.   \n",
       "12231            998          5410      Россия  г. Санкт-Петербург   \n",
       "12232            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "11292         17460      1      0.0      0.0      0.0      0.0      0.0   \n",
       "11293         10942      1     62.0    145.0    124.0    181.0    208.0   \n",
       "11294         10942      1      0.0      0.0      0.0      0.0      0.0   \n",
       "11295         10942      1      0.0     41.0     83.0     82.0     42.0   \n",
       "11296         13301      1     40.0     40.0      0.0     45.0     50.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "12228         17460      1      0.0      0.0      0.0      0.0      0.0   \n",
       "12229         18079      1      5.0      5.0     10.0     10.0      0.0   \n",
       "12230         14956      1    121.0    129.0    117.0    115.0    102.0   \n",
       "12231         14956      1    120.0    120.0     80.0    120.0    140.0   \n",
       "12232         10737      1     20.0      0.0     20.0     40.0     40.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "11292      0.0      79.166667     0.0     0.0  \n",
       "11293    207.0      95.250000     0.5    17.0  \n",
       "11294      0.0      39.166667     0.0     0.0  \n",
       "11295      0.0      24.000000    21.0     0.0  \n",
       "11296     45.0      32.500000     2.5     0.0  \n",
       "...        ...            ...     ...     ...  \n",
       "12228      0.0       0.000000     0.0     0.0  \n",
       "12229      6.0       5.750000     3.0     5.0  \n",
       "12230     29.0      86.250000    36.5    73.0  \n",
       "12231    100.0     119.916667    20.0   100.0  \n",
       "12232     40.0      16.666667     0.0    40.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 12232\n",
      "TEST:  12233 ... 13173\n",
      "Обучающий набор: 13.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>12233</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>62.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12234</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>2</td>\n",
       "      <td>145.0</td>\n",
       "      <td>124.0</td>\n",
       "      <td>181.0</td>\n",
       "      <td>208.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>96.666667</td>\n",
       "      <td>95.0</td>\n",
       "      <td>72.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12235</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>39.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12236</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>2</td>\n",
       "      <td>41.0</td>\n",
       "      <td>83.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12237</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>2</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>29.166667</td>\n",
       "      <td>22.5</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13169</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13170</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>2</td>\n",
       "      <td>5.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.750000</td>\n",
       "      <td>0.5</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13171</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>2</td>\n",
       "      <td>129.0</td>\n",
       "      <td>117.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>92.333333</td>\n",
       "      <td>22.0</td>\n",
       "      <td>74.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13172</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>2</td>\n",
       "      <td>120.0</td>\n",
       "      <td>80.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>118.250000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>180.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13173</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>2</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "12233            124          7278      Россия     Респ. Татарстан   \n",
       "12234            133             0  Белоруссия        Минская обл.   \n",
       "12235            133             0  Белоруссия    Могилевская обл.   \n",
       "12236            133             0  Белоруссия            г. Минск   \n",
       "12237            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "13169            986          9943      Россия     Смоленская обл.   \n",
       "13170            998             0      Россия  Ленинградская обл.   \n",
       "13171            998          3380      Россия  Ленинградская обл.   \n",
       "13172            998          5410      Россия  г. Санкт-Петербург   \n",
       "13173            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "12233         17460      2      0.0      0.0      0.0      0.0      0.0   \n",
       "12234         10942      2    145.0    124.0    181.0    208.0    207.0   \n",
       "12235         10942      2      0.0      0.0      0.0      0.0      0.0   \n",
       "12236         10942      2     41.0     83.0     82.0     42.0      0.0   \n",
       "12237         13301      2     40.0      0.0     45.0     50.0     45.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "13169         17460      2      0.0      0.0      0.0      0.0      0.0   \n",
       "13170         18079      2      5.0     10.0     10.0      0.0      6.0   \n",
       "13171         14956      2    129.0    117.0    115.0    102.0     29.0   \n",
       "13172         14956      2    120.0     80.0    120.0    140.0    100.0   \n",
       "13173         10737      2      0.0     20.0     40.0     40.0     40.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "12233      0.0      62.500000     0.0     0.0  \n",
       "12234     17.0      96.666667    95.0    72.0  \n",
       "12235      0.0      39.166667     0.0     0.0  \n",
       "12236      0.0      20.666667     0.0     0.0  \n",
       "12237      0.0      29.166667    22.5    50.0  \n",
       "...        ...            ...     ...     ...  \n",
       "13169      0.0       0.000000     0.0    21.0  \n",
       "13170      5.0       5.750000     0.5     5.0  \n",
       "13171     73.0      92.333333    22.0    74.0  \n",
       "13172    100.0     118.250000     0.0   180.0  \n",
       "13173     40.0      20.000000     0.0     0.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 13173\n",
      "TEST:  13174 ... 14114\n",
      "Обучающий набор: 14.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>13174</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.833333</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13175</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>3</td>\n",
       "      <td>124.0</td>\n",
       "      <td>181.0</td>\n",
       "      <td>208.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>102.666667</td>\n",
       "      <td>27.5</td>\n",
       "      <td>250.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13176</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>32.500000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13177</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>3</td>\n",
       "      <td>83.0</td>\n",
       "      <td>82.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13178</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>29.166667</td>\n",
       "      <td>25.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14110</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>3</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>1.750000</td>\n",
       "      <td>10.5</td>\n",
       "      <td>63.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14111</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>3</td>\n",
       "      <td>10.0</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.750000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14112</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>3</td>\n",
       "      <td>117.0</td>\n",
       "      <td>115.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>98.500000</td>\n",
       "      <td>0.5</td>\n",
       "      <td>122.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14113</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>3</td>\n",
       "      <td>80.0</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>123.333333</td>\n",
       "      <td>40.0</td>\n",
       "      <td>180.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14114</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>3</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>20.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "13174            124          7278      Россия     Респ. Татарстан   \n",
       "13175            133             0  Белоруссия        Минская обл.   \n",
       "13176            133             0  Белоруссия    Могилевская обл.   \n",
       "13177            133             0  Белоруссия            г. Минск   \n",
       "13178            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "14110            986          9943      Россия     Смоленская обл.   \n",
       "14111            998             0      Россия  Ленинградская обл.   \n",
       "14112            998          3380      Россия  Ленинградская обл.   \n",
       "14113            998          5410      Россия  г. Санкт-Петербург   \n",
       "14114            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "13174         17460      3      0.0      0.0      0.0      0.0      0.0   \n",
       "13175         10942      3    124.0    181.0    208.0    207.0     17.0   \n",
       "13176         10942      3      0.0      0.0      0.0      0.0      0.0   \n",
       "13177         10942      3     83.0     82.0     42.0      0.0      0.0   \n",
       "13178         13301      3      0.0     45.0     50.0     45.0      0.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "14110         17460      3      0.0      0.0      0.0      0.0      0.0   \n",
       "14111         18079      3     10.0     10.0      0.0      6.0      5.0   \n",
       "14112         14956      3    117.0    115.0    102.0     29.0     73.0   \n",
       "14113         14956      3     80.0    120.0    140.0    100.0    100.0   \n",
       "14114         10737      3     20.0     40.0     40.0     40.0     40.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "13174      0.0      45.833333     0.0     0.0  \n",
       "13175     72.0     102.666667    27.5   250.0  \n",
       "13176      0.0      32.500000     0.0     0.0  \n",
       "13177      0.0      20.666667     0.0     0.0  \n",
       "13178     50.0      29.166667    25.0    40.0  \n",
       "...        ...            ...     ...     ...  \n",
       "14110     21.0       1.750000    10.5    63.0  \n",
       "14111      5.0       5.750000     0.0     5.0  \n",
       "14112     74.0      98.500000     0.5   122.0  \n",
       "14113    180.0     123.333333    40.0   180.0  \n",
       "14114      0.0      20.000000    20.0    20.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 14114\n",
      "TEST:  14115 ... 15055\n",
      "Обучающий набор: 15.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>14115</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>29.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14116</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>4</td>\n",
       "      <td>181.0</td>\n",
       "      <td>208.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>123.500000</td>\n",
       "      <td>89.0</td>\n",
       "      <td>394.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14117</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>166.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14118</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>4</td>\n",
       "      <td>82.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.666667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14119</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>4</td>\n",
       "      <td>45.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>32.500000</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15051</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>4</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>21.0</td>\n",
       "      <td>125.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15052</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>4</td>\n",
       "      <td>10.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>6.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15053</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>4</td>\n",
       "      <td>115.0</td>\n",
       "      <td>102.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>102.000000</td>\n",
       "      <td>24.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15054</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>4</td>\n",
       "      <td>120.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>125.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15055</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>4</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>20.000000</td>\n",
       "      <td>10.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "14115            124          7278      Россия     Респ. Татарстан   \n",
       "14116            133             0  Белоруссия        Минская обл.   \n",
       "14117            133             0  Белоруссия    Могилевская обл.   \n",
       "14118            133             0  Белоруссия            г. Минск   \n",
       "14119            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "15051            986          9943      Россия     Смоленская обл.   \n",
       "15052            998             0      Россия  Ленинградская обл.   \n",
       "15053            998          3380      Россия  Ленинградская обл.   \n",
       "15054            998          5410      Россия  г. Санкт-Петербург   \n",
       "15055            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "14115         17460      4      0.0      0.0      0.0      0.0      0.0   \n",
       "14116         10942      4    181.0    208.0    207.0     17.0     72.0   \n",
       "14117         10942      4      0.0      0.0      0.0      0.0      0.0   \n",
       "14118         10942      4     82.0     42.0      0.0      0.0      0.0   \n",
       "14119         13301      4     45.0     50.0     45.0      0.0     50.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "15051         17460      4      0.0      0.0      0.0      0.0     21.0   \n",
       "15052         18079      4     10.0      0.0      6.0      5.0      5.0   \n",
       "15053         14956      4    115.0    102.0     29.0     73.0     74.0   \n",
       "15054         14956      4    120.0    140.0    100.0    100.0    180.0   \n",
       "15055         10737      4     40.0     40.0     40.0     40.0      0.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "14115      0.0      29.166667     0.0     0.0  \n",
       "14116    250.0     123.500000    89.0   394.0  \n",
       "14117      0.0      20.666667     0.0   166.0  \n",
       "14118      0.0      20.666667     0.0    21.0  \n",
       "14119     40.0      32.500000     5.0     0.0  \n",
       "...        ...            ...     ...     ...  \n",
       "15051     63.0       7.000000    21.0   125.0  \n",
       "15052      5.0       6.166667     0.0     0.0  \n",
       "15053    122.0     102.000000    24.0   100.0  \n",
       "15054    180.0     125.000000     0.0   100.0  \n",
       "15055     20.0      20.000000    10.0    40.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 15055\n",
      "TEST:  15056 ... 15996\n",
      "Обучающий набор: 16.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15056</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>13.750000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15057</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>5</td>\n",
       "      <td>208.0</td>\n",
       "      <td>207.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>394.0</td>\n",
       "      <td>153.333333</td>\n",
       "      <td>72.0</td>\n",
       "      <td>288.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15058</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>166.0</td>\n",
       "      <td>25.916667</td>\n",
       "      <td>83.0</td>\n",
       "      <td>62.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15059</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>5</td>\n",
       "      <td>42.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>22.416667</td>\n",
       "      <td>10.5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15060</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>5</td>\n",
       "      <td>50.0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>29.166667</td>\n",
       "      <td>20.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15992</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>17.416667</td>\n",
       "      <td>31.0</td>\n",
       "      <td>84.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15993</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>5</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.500000</td>\n",
       "      <td>2.5</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15994</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>5</td>\n",
       "      <td>102.0</td>\n",
       "      <td>29.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>102.500000</td>\n",
       "      <td>11.0</td>\n",
       "      <td>15.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15995</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>5</td>\n",
       "      <td>140.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>123.333333</td>\n",
       "      <td>40.0</td>\n",
       "      <td>140.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15996</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>5</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>23.333333</td>\n",
       "      <td>10.0</td>\n",
       "      <td>20.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "15056            124          7278      Россия     Респ. Татарстан   \n",
       "15057            133             0  Белоруссия        Минская обл.   \n",
       "15058            133             0  Белоруссия    Могилевская обл.   \n",
       "15059            133             0  Белоруссия            г. Минск   \n",
       "15060            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "15992            986          9943      Россия     Смоленская обл.   \n",
       "15993            998             0      Россия  Ленинградская обл.   \n",
       "15994            998          3380      Россия  Ленинградская обл.   \n",
       "15995            998          5410      Россия  г. Санкт-Петербург   \n",
       "15996            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "15056         17460      5      0.0      0.0      0.0      0.0      0.0   \n",
       "15057         10942      5    208.0    207.0     17.0     72.0    250.0   \n",
       "15058         10942      5      0.0      0.0      0.0      0.0      0.0   \n",
       "15059         10942      5     42.0      0.0      0.0      0.0      0.0   \n",
       "15060         13301      5     50.0     45.0      0.0     50.0     40.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "15992         17460      5      0.0      0.0      0.0     21.0     63.0   \n",
       "15993         18079      5      0.0      6.0      5.0      5.0      5.0   \n",
       "15994         14956      5    102.0     29.0     73.0     74.0    122.0   \n",
       "15995         14956      5    140.0    100.0    100.0    180.0    180.0   \n",
       "15996         10737      5     40.0     40.0     40.0      0.0     20.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "15056      0.0      13.750000     0.0     0.0  \n",
       "15057    394.0     153.333333    72.0   288.0  \n",
       "15058    166.0      25.916667    83.0    62.0  \n",
       "15059     21.0      22.416667    10.5     0.0  \n",
       "15060      0.0      29.166667    20.0     0.0  \n",
       "...        ...            ...     ...     ...  \n",
       "15992    125.0      17.416667    31.0    84.0  \n",
       "15993      0.0       5.500000     2.5     3.0  \n",
       "15994    100.0     102.500000    11.0    15.0  \n",
       "15995    100.0     123.333333    40.0   140.0  \n",
       "15996     40.0      23.333333    10.0    20.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 15996\n",
      "TEST:  15997 ... 16937\n",
      "Обучающий набор: 17.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>15997</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15998</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>6</td>\n",
       "      <td>207.0</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>394.0</td>\n",
       "      <td>288.0</td>\n",
       "      <td>169.166667</td>\n",
       "      <td>53.0</td>\n",
       "      <td>210.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15999</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>166.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>52.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16000</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>22.416667</td>\n",
       "      <td>10.5</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16001</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>6</td>\n",
       "      <td>45.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>29.166667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16933</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>6</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>24.416667</td>\n",
       "      <td>20.5</td>\n",
       "      <td>84.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16934</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>6</td>\n",
       "      <td>6.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.333333</td>\n",
       "      <td>1.5</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16935</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>6</td>\n",
       "      <td>29.0</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>93.166667</td>\n",
       "      <td>42.5</td>\n",
       "      <td>30.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16936</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>6</td>\n",
       "      <td>100.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>123.333333</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16937</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>6</td>\n",
       "      <td>40.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>23.333333</td>\n",
       "      <td>10.0</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "15997            124          7278      Россия     Респ. Татарстан   \n",
       "15998            133             0  Белоруссия        Минская обл.   \n",
       "15999            133             0  Белоруссия    Могилевская обл.   \n",
       "16000            133             0  Белоруссия            г. Минск   \n",
       "16001            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "16933            986          9943      Россия     Смоленская обл.   \n",
       "16934            998             0      Россия  Ленинградская обл.   \n",
       "16935            998          3380      Россия  Ленинградская обл.   \n",
       "16936            998          5410      Россия  г. Санкт-Петербург   \n",
       "16937            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "15997         17460      6      0.0      0.0      0.0      0.0      0.0   \n",
       "15998         10942      6    207.0     17.0     72.0    250.0    394.0   \n",
       "15999         10942      6      0.0      0.0      0.0      0.0    166.0   \n",
       "16000         10942      6      0.0      0.0      0.0      0.0     21.0   \n",
       "16001         13301      6     45.0      0.0     50.0     40.0      0.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "16933         17460      6      0.0      0.0     21.0     63.0    125.0   \n",
       "16934         18079      6      6.0      5.0      5.0      5.0      0.0   \n",
       "16935         14956      6     29.0     73.0     74.0    122.0    100.0   \n",
       "16936         14956      6    100.0    100.0    180.0    180.0    100.0   \n",
       "16937         10737      6     40.0     40.0      0.0     20.0     40.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "15997      0.0       5.166667     0.0     0.0  \n",
       "15998    288.0     169.166667    53.0   210.0  \n",
       "15999     62.0      19.000000    52.0     0.0  \n",
       "16000      0.0      22.416667    10.5     0.0  \n",
       "16001      0.0      29.166667     0.0    50.0  \n",
       "...        ...            ...     ...     ...  \n",
       "16933     84.0      24.416667    20.5    84.0  \n",
       "16934      3.0       5.333333     1.5     3.0  \n",
       "16935     15.0      93.166667    42.5    30.0  \n",
       "16936    140.0     123.333333    20.0    40.0  \n",
       "16937     20.0      23.333333    10.0    21.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "TRAIN:  0 ... 16937\n",
      "TEST:  16938 ... 17878\n",
      "Обучающий набор: 18.000000\n",
      "Тестовый набор: 1\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "      <th>target</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>16938</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16939</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>394.0</td>\n",
       "      <td>288.0</td>\n",
       "      <td>210.0</td>\n",
       "      <td>179.833333</td>\n",
       "      <td>39.0</td>\n",
       "      <td>249.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16940</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>166.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>31.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16941</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>22.416667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16942</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>25.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17874</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>31.416667</td>\n",
       "      <td>0.0</td>\n",
       "      <td>83.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17875</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.750000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17876</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>85.583333</td>\n",
       "      <td>7.5</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17877</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>118.333333</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17878</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>7</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>25.083333</td>\n",
       "      <td>0.5</td>\n",
       "      <td>21.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 15 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       material_code  company_code     country              region  \\\n",
       "16938            124          7278      Россия     Респ. Татарстан   \n",
       "16939            133             0  Белоруссия        Минская обл.   \n",
       "16940            133             0  Белоруссия    Могилевская обл.   \n",
       "16941            133             0  Белоруссия            г. Минск   \n",
       "16942            133             0   Казахстан       г. Нур-Султан   \n",
       "...              ...           ...         ...                 ...   \n",
       "17874            986          9943      Россия     Смоленская обл.   \n",
       "17875            998             0      Россия  Ленинградская обл.   \n",
       "17876            998          3380      Россия  Ленинградская обл.   \n",
       "17877            998          5410      Россия  г. Санкт-Петербург   \n",
       "17878            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "       manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "16938         17460      7      0.0      0.0      0.0      0.0      0.0   \n",
       "16939         10942      7     17.0     72.0    250.0    394.0    288.0   \n",
       "16940         10942      7      0.0      0.0      0.0    166.0     62.0   \n",
       "16941         10942      7      0.0      0.0      0.0     21.0      0.0   \n",
       "16942         13301      7      0.0     50.0     40.0      0.0      0.0   \n",
       "...             ...    ...      ...      ...      ...      ...      ...   \n",
       "17874         17460      7      0.0     21.0     63.0    125.0     84.0   \n",
       "17875         18079      7      5.0      5.0      5.0      0.0      3.0   \n",
       "17876         14956      7     73.0     74.0    122.0    100.0     15.0   \n",
       "17877         14956      7    100.0    180.0    180.0    100.0    140.0   \n",
       "17878         10737      7     40.0      0.0     20.0     40.0     20.0   \n",
       "\n",
       "       vol_tm1  last_year_avg  mdad_2  target  \n",
       "16938      0.0       0.000000     0.0     0.0  \n",
       "16939    210.0     179.833333    39.0   249.0  \n",
       "16940      0.0      19.000000    31.0     0.0  \n",
       "16941      0.0      22.416667     0.0     6.0  \n",
       "16942     50.0      30.000000    25.0     0.0  \n",
       "...        ...            ...     ...     ...  \n",
       "17874     84.0      31.416667     0.0    83.0  \n",
       "17875      3.0       4.750000     0.0     9.0  \n",
       "17876     30.0      85.583333     7.5    50.0  \n",
       "17877     40.0     118.333333    50.0     0.0  \n",
       "17878     21.0      25.083333     0.5    21.0  \n",
       "\n",
       "[941 rows x 15 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tscv.get_n_splits()= 17\n"
     ]
    }
   ],
   "source": [
    "for train_index, test_index in tscv.split(cv_features): # tscv.split(X): # tscv.split(cv_features)\n",
    "    print(\"TRAIN: \", train_index[0],\"...\",train_index[-1])\n",
    "    print(\"TEST: \", test_index[0],\"...\",test_index[-1])\n",
    "\n",
    "    X_train, X_test = cv_features.iloc[train_index], cv_features.iloc[test_index]\n",
    "    y_train, y_test = cv_features.iloc[train_index][TARGET], cv_features.iloc[test_index][TARGET]\n",
    "    \n",
    "    print('Обучающий набор: %f' % (len(X_train)/941)) #test_size))\n",
    "    print('Тестовый набор: %d' % (len(X_test)/941)) #test_size))\n",
    "\n",
    "    #display(X_train)\n",
    "    display(X_test)\n",
    "print(\"tscv.get_n_splits()=\",tscv.get_n_splits())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b9f0aa69",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "raw",
   "id": "77810f4f",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:35.448466Z",
     "iopub.status.busy": "2021-04-25T10:51:35.447594Z",
     "iopub.status.idle": "2021-04-25T10:51:35.451342Z",
     "shell.execute_reply": "2021-04-25T10:51:35.451842Z"
    },
    "id": "AaNAOFfSj56e",
    "papermill": {
     "duration": 0.082432,
     "end_time": "2021-04-25T10:51:35.451996",
     "exception": false,
     "start_time": "2021-04-25T10:51:35.369564",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "if TEST:\n",
    "    data = data[:1000]\n",
    "    print(\"TEST MODE, Data shape = \",data.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "7051c726",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:37.599541Z",
     "iopub.status.busy": "2021-04-25T10:51:37.598469Z",
     "iopub.status.idle": "2021-04-25T10:51:37.605466Z",
     "shell.execute_reply": "2021-04-25T10:51:37.604902Z"
    },
    "id": "5yQ9Qp9Vj56f",
    "outputId": "1488f05d-b4f5-404c-8e95-8056ed6d6c2e",
    "papermill": {
     "duration": 0.092475,
     "end_time": "2021-04-25T10:51:37.605629",
     "exception": false,
     "start_time": "2021-04-25T10:51:37.513154",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['material_code', 'company_code', 'country', 'region', 'manager_code', 'month']\n",
      "['vol_tm6', 'vol_tm5', 'vol_tm4', 'vol_tm3', 'vol_tm2', 'vol_tm1', 'last_year_avg', 'mdad_2']\n"
     ]
    }
   ],
   "source": [
    "# создаем списки категориальных признаков\n",
    "#cat_columns = data.select_dtypes(include='object').columns\n",
    "cat_columns = CAT_COLS\n",
    "\n",
    "# создаем список количественных признаков\n",
    "#num_columns = train.select_dtypes(exclude='object').columns.tolist()\n",
    "num_columns =  [x for x in cv_features.columns.to_list() if x not in CAT_COLS + [TARGET]]\n",
    "print(cat_columns)\n",
    "print(num_columns)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "urban-parker",
   "metadata": {
    "id": "ydsW51MDj56g",
    "papermill": {
     "duration": 0.070321,
     "end_time": "2021-04-25T10:51:37.747471",
     "exception": false,
     "start_time": "2021-04-25T10:51:37.677150",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "> # ********  Phase 1 *************"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "freelance-annex",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:37.897911Z",
     "iopub.status.busy": "2021-04-25T10:51:37.896585Z",
     "iopub.status.idle": "2021-04-25T10:51:37.900242Z",
     "shell.execute_reply": "2021-04-25T10:51:37.899681Z"
    },
    "id": "ZWqH1pSAj56g",
    "papermill": {
     "duration": 0.080284,
     "end_time": "2021-04-25T10:51:37.900455",
     "exception": false,
     "start_time": "2021-04-25T10:51:37.820171",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# создаем конвейеры\n",
    "cat_pipe = Pipeline([('enc', \n",
    "                      TargetEncoder(),\n",
    "                      #OneHotEncoder(sparse=False, handle_unknown='ignore') \n",
    "                     )])\n",
    "num_pipe = Pipeline([('scal', None)]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "civil-roots",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:38.050524Z",
     "iopub.status.busy": "2021-04-25T10:51:38.048547Z",
     "iopub.status.idle": "2021-04-25T10:51:38.051231Z",
     "shell.execute_reply": "2021-04-25T10:51:38.051765Z"
    },
    "id": "-MiFAGrdj56g",
    "papermill": {
     "duration": 0.08017,
     "end_time": "2021-04-25T10:51:38.051910",
     "exception": false,
     "start_time": "2021-04-25T10:51:37.971740",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# создаем список трехэлементных кортежей, в котором\n",
    "# первый элемент кортежа - название конвейера с\n",
    "# преобразованиями для определенного типа признаков\n",
    "transformers = [('num', num_pipe, num_columns),\n",
    "                ('cat', cat_pipe, cat_columns)]\n",
    "\n",
    "# передаем список трансформеров в ColumnTransformer\n",
    "transformer = ColumnTransformer(transformers=transformers)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "swiss-adoption",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:38.205451Z",
     "iopub.status.busy": "2021-04-25T10:51:38.203525Z",
     "iopub.status.idle": "2021-04-25T10:51:38.206229Z",
     "shell.execute_reply": "2021-04-25T10:51:38.206883Z"
    },
    "id": "Z1V4HwqWj56h",
    "papermill": {
     "duration": 0.0832,
     "end_time": "2021-04-25T10:51:38.207045",
     "exception": false,
     "start_time": "2021-04-25T10:51:38.123845",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_1:\n",
    "    params2 = params   \n",
    "    # задаем итоговый конвейер\n",
    "    ml_pipe = Pipeline([('tr', transformer), \n",
    "                        ('ml', xgb.XGBRegressor(**params) )])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "responsible-canvas",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:38.360061Z",
     "iopub.status.busy": "2021-04-25T10:51:38.359232Z",
     "iopub.status.idle": "2021-04-25T10:51:38.362318Z",
     "shell.execute_reply": "2021-04-25T10:51:38.362833Z"
    },
    "id": "BNzybeXGj56h",
    "papermill": {
     "duration": 0.082989,
     "end_time": "2021-04-25T10:51:38.362986",
     "exception": false,
     "start_time": "2021-04-25T10:51:38.279997",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "N_ESTIMATORS_RANG = list(range(10,500,1))#  [50000] #[5000] #[500] #\n",
    "RANG_LEARNING_RATE =   list(np.arange(0.01,0.1,0.005)) # 0.0015 #list(np.arange(5e-3,1e-1,5e-3)) # [0.005]\n",
    "\n",
    "if Phase_1:\n",
    "    # задаем сетку гиперпараметров\n",
    "    param_grid = [{\n",
    "                'tr__cat__enc': [LabelEncoder(), \n",
    "                                 OrdinalEncoder(),\n",
    "                                 OneHotEncoder(sparse=False, handle_unknown='ignore'),\n",
    "                                 TargetEncoder(),\n",
    "                                 CatBoostEncoder(),\n",
    "                                 LeaveOneOutEncoder()\n",
    "                                ],\n",
    "                'tr__num__scal': [# StandardScaler(),\n",
    "                                  None\n",
    "                                 ],\n",
    "                'ml__learning_rate': RANG_LEARNING_RATE,\n",
    "                'ml__n_estimators' : N_ESTIMATORS_RANG\n",
    "    }]\n",
    "    \n",
    "    if TEST:\n",
    "            param_grid = [{\n",
    "                    'tr__cat__enc': [#TargetEncoder(),\n",
    "                                     LabelEncoder(), \n",
    "                                     #OrdinalEncoder(),\n",
    "                                     #OneHotEncoder(sparse=False, handle_unknown='ignore')\n",
    "                                    ],\n",
    "                    'tr__num__scal': [None,  StandardScaler()],\n",
    "                    'ml__learning_rate': [0.03,0.02],\n",
    "                    'ml__n_estimators' : [20,30]\n",
    "    }]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "2c956d16",
   "metadata": {},
   "outputs": [],
   "source": [
    "# обучаем модель, используя логарифмирование зависимой \n",
    "train, y_train = cv_features[FTS_COLS], np.log1p(cv_features[TARGET])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "fixed-settle",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:38.517649Z",
     "iopub.status.busy": "2021-04-25T10:51:38.516591Z",
     "iopub.status.idle": "2021-04-25T10:51:38.522067Z",
     "shell.execute_reply": "2021-04-25T10:51:38.521513Z"
    },
    "id": "toiOlZODj56h",
    "outputId": "4b8b1cc2-3607-4a94-aa12-a9f1b228a10d",
    "papermill": {
     "duration": 0.085583,
     "end_time": "2021-04-25T10:51:38.522242",
     "exception": false,
     "start_time": "2021-04-25T10:51:38.436659",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 0 ns\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "rmsle = lambda y_true, y_pred: \\\n",
    "                np.sqrt(mean_squared_log_error(\n",
    "                    y_true, pd.Series(y_pred).clip(lower=0)\n",
    "                ))\n",
    "if Phase_1:\n",
    "    # создаем экземпляр класса RandomizedSearchCV или GridSearchCV, передав конвейер,\n",
    "    # сетку гиперпараметров и указав количество\n",
    "    # блоков перекрестной проверки, отключив запись метрик \n",
    "    # для обучающих блоков перекрестной проверки в атрибут cv_results_\n",
    "    #gs = GridSearchCV(\n",
    "    gs = RandomizedSearchCV( \n",
    "                      ml_pipe, \n",
    "                      param_grid, \n",
    "                      cv=tscv,   # CV, \n",
    "                      scoring=make_scorer(rmsle, greater_is_better=False), #True), #False),#\n",
    "                      n_jobs=6, #-1, \n",
    "                      return_train_score=False,\n",
    "                      verbose=10, #3,\n",
    "                      random_state=SEED,\n",
    "                    n_iter = 100\n",
    "                     )\n",
    "    # выполняем решетчатый поиск\n",
    "    gs.fit(train, y_train)\n",
    "    \n",
    "    \n",
    "    # записываем оптимальные значения гиперпараметров\n",
    "    OPT_PARAMS_PIPE = gs.best_params_ \n",
    "    display(gs.best_params_, gs.best_score_)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "d1698be5",
   "metadata": {},
   "source": [
    "0.6340411759257776)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "surface-advance",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:38.674454Z",
     "iopub.status.busy": "2021-04-25T10:51:38.673577Z",
     "iopub.status.idle": "2021-04-25T10:51:38.677448Z",
     "shell.execute_reply": "2021-04-25T10:51:38.676932Z"
    },
    "id": "wPDat-nmj56i",
    "papermill": {
     "duration": 0.081992,
     "end_time": "2021-04-25T10:51:38.677592",
     "exception": false,
     "start_time": "2021-04-25T10:51:38.595600",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_1:\n",
    "    #y_probas = gs.predict_proba(test)\n",
    "    # смотрим наилучшие значения гиперпараметров\n",
    "    print('Наилучшие значения гиперпараметров: {}'.format(OPT_PARAMS_PIPE))\n",
    "    # смотрим наилучшее значение SCORE\n",
    "    print('Наилучшее значение SCORE: {:.3f}'.format(gs.best_score_))\n",
    "    # смотрим значение AUC на тестовой выборке\n",
    "    #print('Значение SCORE на тестовой выборке: {:.3f}'.format(\n",
    "    #   roc_auc_score(y_test, y_probas[:, 1] )))"
   ]
  },
  {
   "cell_type": "raw",
   "id": "dcd243c6",
   "metadata": {},
   "source": [
    "Наилучшие значения гиперпараметров: {'tr__num__scal': None, 'tr__cat__enc': CatBoostEncoder(), 'ml__n_estimators': 330, 'ml__learning_rate': 0.05499999999999999}\n",
    "Наилучшее значение SCORE: -0.629"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "26600870",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "serial-socket",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:39.723337Z",
     "iopub.status.busy": "2021-04-25T10:51:39.722234Z",
     "iopub.status.idle": "2021-04-25T10:51:39.725639Z",
     "shell.execute_reply": "2021-04-25T10:51:39.726200Z"
    },
    "id": "zCumPqG-j56i",
    "papermill": {
     "duration": 0.089457,
     "end_time": "2021-04-25T10:51:39.726377",
     "exception": false,
     "start_time": "2021-04-25T10:51:39.636920",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_1:\n",
    "    # увеличиваем количество выводимых строк\n",
    "    pd.set_option('display.max_rows', 300)\n",
    "\n",
    "    # выводим результаты\n",
    "    cv_results = pd.DataFrame(gs.cv_results_)[['mean_test_score',\n",
    "                                               'param_ml__n_estimators',\n",
    "                                               'param_ml__learning_rate',\n",
    "                                               'param_tr__cat__enc',\n",
    "                                               'param_tr__num__scal'\n",
    "                                               ]]\n",
    "    cv_results = cv_results.sort_values(by='mean_test_score', ascending=False).reset_index(drop=True)\n",
    "\n",
    "    for col in cv_results.columns[cv_results.columns.str.contains('enc')]:\n",
    "        if col in 'mean_test_score':\n",
    "            continue\n",
    "\n",
    "        cv_results[col] = cv_results[col].apply(lambda x: type(x).__name__)\n",
    "\n",
    "    display(cv_results)\n",
    "    \n",
    "    with open(NAME_RUN_LOG, 'at', encoding='utf-8') as logfile:\n",
    "        print('Временная метка окончания ФАЗЫ 1 : {}'.format(datetime.now().strftime(\"%d-%m-%Y %H:%M\")), \n",
    "          file=logfile)\n",
    "        print('Наилучшие значения гиперпараметров: {}'.format(gs.best_params_), file=logfile)\n",
    "        print('Наилучшее значение SCORE: {:.3f}'.format(gs.best_score_), file=logfile)\n",
    "        #print('Значение AUC на тестовой выборке: {:.3f}'.format(\n",
    "        #    roc_auc_score(y_test, gs.predict_proba(test)[:, 1])), file=logfile)\n",
    "        print('Таблица значений: ', file=logfile)\n",
    "        #print(display(cv_results), file=logfile)\n",
    "    with open(NAME_RUN_LOG, 'at', encoding='utf-8') as logfile:\n",
    "        cv_results.to_csv(NAME_RUN_LOG, index=False, mode='at')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "metallic-fleet",
   "metadata": {
    "id": "1CNKuN-jj56i",
    "papermill": {
     "duration": 0.075618,
     "end_time": "2021-04-25T10:51:40.195204",
     "exception": false,
     "start_time": "2021-04-25T10:51:40.119586",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "> # ********  Phase 2 *************"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "unlikely-cancellation",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:40.353035Z",
     "iopub.status.busy": "2021-04-25T10:51:40.351809Z",
     "iopub.status.idle": "2021-04-25T10:51:40.355640Z",
     "shell.execute_reply": "2021-04-25T10:51:40.355028Z"
    },
    "id": "itTSx5MTj56j",
    "papermill": {
     "duration": 0.085734,
     "end_time": "2021-04-25T10:51:40.355769",
     "exception": false,
     "start_time": "2021-04-25T10:51:40.270035",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_2 or Phase_3 or Phase_4:\n",
    "    # трансформеры - ставим сюда лучший \n",
    "    # из найденных в 1-й фазе\n",
    "    upd_cat_pipe = Pipeline([('enc',CatBoostEncoder() )])  \n",
    "    upd_num_pipe = Pipeline([('scal', None)]) # \n",
    "\n",
    "    upd_transformers = [('num', upd_num_pipe, num_columns),\n",
    "                        ('cat', upd_cat_pipe, cat_columns),]\n",
    "\n",
    "    # передаем список трансформеров в ColumnTransformer\n",
    "    upd_transformer = ColumnTransformer(transformers=upd_transformers)\n",
    "\n",
    "    # задаем итоговый конвейер ПОКА ЧТО С НАЧАЛЬНЫМИ НАСТРОЙКАМИ\n",
    "    ml_pipe2 = Pipeline([('tr', upd_transformer), \n",
    "                         ('ml', xgb.XGBRegressor(**params) )])\n",
    "\n",
    "    # УСТАНОВКА В НОВЫЙ PIPE НАИЛУЧШИХ ЗНАЧЕНИЙ НАЙДЕННЫХ В ПРЕДЫДУЩЕЙ ФАЗЕ:  \n",
    "    if Phase_1:  \n",
    "        # присваиваем итоговому конвейеру оптимальные значения гиперпараметров\n",
    "        print('Before modification ml__n_estimators ml_pipe2: ', ml_pipe2.get_params()['ml__n_estimators']) # 'n_estimators'\n",
    "        print('Before modification ml__learning_rate ml_pipe2: ', ml_pipe2.get_params()['ml__learning_rate']) # 'n_estimators'\n",
    "        ml_pipe2.set_params(**OPT_PARAMS_PIPE)\n",
    "        print('After modification ml__n_estimators ml_pipe2: ', ml_pipe2.get_params()['ml__n_estimators'])\n",
    "        print('After modification ml__learning_rate ml_pipe2: ', ml_pipe2.get_params()['ml__learning_rate'])"
   ]
  },
  {
   "cell_type": "raw",
   "id": "dc59387e",
   "metadata": {},
   "source": [
    "ml_pipe2.get_params()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "light-steering",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:40.511370Z",
     "iopub.status.busy": "2021-04-25T10:51:40.510416Z",
     "iopub.status.idle": "2021-04-25T10:51:40.514366Z",
     "shell.execute_reply": "2021-04-25T10:51:40.513745Z"
    },
    "papermill": {
     "duration": 0.083289,
     "end_time": "2021-04-25T10:51:40.514563",
     "exception": false,
     "start_time": "2021-04-25T10:51:40.431274",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "params2 = params3 = params4 = {}\n",
    "\n",
    "if Phase_2: \n",
    "    params2 = {\n",
    "        #'ml__use_label_encoder' : False ,\n",
    "        # (1) гиперпараметры, задающие структуру дерева:\n",
    "        #'tree_method' : 'gpu_hist' , \n",
    "        'ml__max_depth' : IntUniformDistribution(1 , 20),\n",
    "        'ml__min_child_weight' : IntUniformDistribution(1 , 300),\n",
    "        }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "introductory-courtesy",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:40.672603Z",
     "iopub.status.busy": "2021-04-25T10:51:40.671664Z",
     "iopub.status.idle": "2021-04-25T10:51:40.675619Z",
     "shell.execute_reply": "2021-04-25T10:51:40.675078Z"
    },
    "papermill": {
     "duration": 0.085211,
     "end_time": "2021-04-25T10:51:40.675756",
     "exception": false,
     "start_time": "2021-04-25T10:51:40.590545",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    " # (2) гиперпараметры, привносящие случайность в ходе построения дерева:\n",
    "if Phase_3: \n",
    "    params3 = {\n",
    "              'ml__colsample_bytree' : UniformDistribution( 0 , 1.0),\n",
    "              'ml__subsample' : UniformDistribution( 0 , 1.0)\n",
    "             }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "respected-dance",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:40.835676Z",
     "iopub.status.busy": "2021-04-25T10:51:40.834622Z",
     "iopub.status.idle": "2021-04-25T10:51:40.838609Z",
     "shell.execute_reply": "2021-04-25T10:51:40.838049Z"
    },
    "papermill": {
     "duration": 0.087288,
     "end_time": "2021-04-25T10:51:40.838808",
     "exception": false,
     "start_time": "2021-04-25T10:51:40.751520",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# (3) гиперпараметры, задающие регуляризацию функции потерь:\n",
    "if Phase_4: \n",
    "    params4 = {\n",
    "            'ml__lambda' : UniformDistribution( 1e-5 , 1.0),\n",
    "            'ml__alpha' : UniformDistribution( 1e-5 , 1.0),\n",
    "            'ml__gamma' : UniformDistribution( 1e-5 , 1.0)\n",
    "             }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "sized-minnesota",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:40.995605Z",
     "iopub.status.busy": "2021-04-25T10:51:40.994588Z",
     "iopub.status.idle": "2021-04-25T10:51:40.998346Z",
     "shell.execute_reply": "2021-04-25T10:51:40.997785Z"
    },
    "papermill": {
     "duration": 0.08398,
     "end_time": "2021-04-25T10:51:40.998493",
     "exception": false,
     "start_time": "2021-04-25T10:51:40.914513",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_2 or Phase_3 or Phase_4:  \n",
    "    # задаем новое пространство поиска\n",
    "    param_distributions = {**params2,**params3,**params4}\n",
    "    print(param_distributions)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "russian-matrix",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:41.158143Z",
     "iopub.status.busy": "2021-04-25T10:51:41.157019Z",
     "iopub.status.idle": "2021-04-25T10:51:41.160237Z",
     "shell.execute_reply": "2021-04-25T10:51:41.160785Z"
    },
    "id": "VZ8ujEQBj56j",
    "papermill": {
     "duration": 0.086815,
     "end_time": "2021-04-25T10:51:41.160994",
     "exception": false,
     "start_time": "2021-04-25T10:51:41.074179",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_2 or Phase_3 or Phase_4:  \n",
    "    # задаем новое пространство поиска\n",
    "    #param_distributions = {**params2,**params3,**params4}\n",
    " \n",
    "    if TEST:\n",
    "        param_distributions = {'ml__max_depth' : IntUniformDistribution(11, 13),\n",
    "                              'ml__min_child_weight' : IntUniformDistribution(23, 25),}  \n",
    "\n",
    "    # создаем экземпляр класса OptunaSearchCV\n",
    "    optuna_search = OptunaSearchCV(\n",
    "        ml_pipe2,\n",
    "        param_distributions,\n",
    "        scoring=make_scorer(rmsle, greater_is_better=False),\n",
    "        n_trials=N_TRIALS,\n",
    "        n_jobs=-1,\n",
    "        refit=True,\n",
    "        verbose=1,\n",
    "        cv=tscv,   # CV_O,\n",
    "        random_state=SEED)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "sticky-offer",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:41.320724Z",
     "iopub.status.busy": "2021-04-25T10:51:41.319614Z",
     "iopub.status.idle": "2021-04-25T10:51:41.325871Z",
     "shell.execute_reply": "2021-04-25T10:51:41.324961Z"
    },
    "id": "3Tbb9_ryj56k",
    "papermill": {
     "duration": 0.087109,
     "end_time": "2021-04-25T10:51:41.326081",
     "exception": false,
     "start_time": "2021-04-25T10:51:41.238972",
     "status": "completed"
    },
    "scrolled": true,
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 0 ns\n"
     ]
    }
   ],
   "source": [
    "%%time\n",
    "if Phase_2 or Phase_3 or Phase_4:  \n",
    "    # выполняем оптимизацию\n",
    "    optuna_search.fit(train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "suspected-investor",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:41.488722Z",
     "iopub.status.busy": "2021-04-25T10:51:41.487600Z",
     "iopub.status.idle": "2021-04-25T10:51:41.491463Z",
     "shell.execute_reply": "2021-04-25T10:51:41.490847Z"
    },
    "id": "SyreK__Qj56l",
    "papermill": {
     "duration": 0.088597,
     "end_time": "2021-04-25T10:51:41.491593",
     "exception": false,
     "start_time": "2021-04-25T10:51:41.402996",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "if Phase_2 or Phase_3 or Phase_4:  \n",
    "    # записываем оптимальные значения гиперпараметров optuna\n",
    "    opt_optuna_params_pipe = optuna_search.best_params_\n",
    "    if Phase_1:\n",
    "        opt_optuna_params_pipe['ml__learning_rate'] = OPT_PARAMS_PIPE['ml__learning_rate']\n",
    "        opt_optuna_params_pipe['ml__n_estimators'] = OPT_PARAMS_PIPE['ml__n_estimators']\n",
    "\n",
    "    # печатаем наилучшие значения гиперпараметров\n",
    "    print('Наилучшие значения гиперпараметров: {}'.format(opt_optuna_params_pipe))\n",
    "    # печатаем наилучшее значение SCORE\n",
    "    print('Наилучшее значение SCORE: {:.3f}'.format(optuna_search.best_score_))\n",
    "    # смотрим значение SCORE на тестовой выборке\n",
    "    #print('SCORE на тестовой выборке: {:.3f}'.format(\n",
    "    #    rsmle(y_test, optuna_search.predict_proba(test)[:, 1])))\n",
    "    print('')\n",
    "    with open(NAME_RUN_LOG, 'at', encoding='utf-8') as logfile:\n",
    "        print('/nВременная метка окончания ФАЗЫ 2 : {}'.format(datetime.now().strftime(\"%d-%m-%Y %H:%M\")), \n",
    "          file=logfile)\n",
    "        print('Наилучшие значения гиперпараметров найденых optuna: \\n{}'.format(opt_optuna_params_pipe), file=logfile)\n",
    "        print('Наилучшее значение SCORE: {:.3f}'.format(optuna_search.best_score_), file=logfile)\n",
    "        #print('SCORE на тестовой выборке: {:.3f}\\n'.format(\n",
    "        #    rsmle(y_test, optuna_search.predict_proba(test)[:, 1])), file=logfile)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cardiovascular-conservative",
   "metadata": {
    "id": "XEUoguQDj56m",
    "papermill": {
     "duration": 0.074747,
     "end_time": "2021-04-25T10:51:41.642008",
     "exception": false,
     "start_time": "2021-04-25T10:51:41.567261",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "> # ********  Final phase *************"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "outdoor-feeding",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:41.797081Z",
     "iopub.status.busy": "2021-04-25T10:51:41.796115Z",
     "iopub.status.idle": "2021-04-25T10:51:41.799982Z",
     "shell.execute_reply": "2021-04-25T10:51:41.799434Z"
    },
    "papermill": {
     "duration": 0.084102,
     "end_time": "2021-04-25T10:51:41.800134",
     "exception": false,
     "start_time": "2021-04-25T10:51:41.716032",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# high parameters at the end\n",
    "if HIGH_PARAM_END:\n",
    "        opt_optuna_params_pipe['ml__learning_rate'] = 20000\n",
    "        opt_optuna_params_pipe['ml__n_estimators'] = 0.0021"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "mobile-entity",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:41.958120Z",
     "iopub.status.busy": "2021-04-25T10:51:41.956950Z",
     "iopub.status.idle": "2021-04-25T10:51:41.964255Z",
     "shell.execute_reply": "2021-04-25T10:51:41.963410Z"
    },
    "id": "iexbKXzIj56m",
    "papermill": {
     "duration": 0.088831,
     "end_time": "2021-04-25T10:51:41.964409",
     "exception": false,
     "start_time": "2021-04-25T10:51:41.875578",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# формируем полный массив меток и массив признаков\n",
    "# формируем полный массив тренировочных данных\n",
    "# формируем полный массив меток и массив признаков   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "a5b6c0ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 17879 entries, 0 to 17878\n",
      "Data columns (total 15 columns):\n",
      " #   Column         Non-Null Count  Dtype   \n",
      "---  ------         --------------  -----   \n",
      " 0   material_code  17879 non-null  int64   \n",
      " 1   company_code   17879 non-null  int64   \n",
      " 2   country        17879 non-null  category\n",
      " 3   region         17879 non-null  category\n",
      " 4   manager_code   17879 non-null  int64   \n",
      " 5   month          17879 non-null  int64   \n",
      " 6   vol_tm6        17879 non-null  float64 \n",
      " 7   vol_tm5        17879 non-null  float64 \n",
      " 8   vol_tm4        17879 non-null  float64 \n",
      " 9   vol_tm3        17879 non-null  float64 \n",
      " 10  vol_tm2        17879 non-null  float64 \n",
      " 11  vol_tm1        17879 non-null  float64 \n",
      " 12  last_year_avg  17879 non-null  float64 \n",
      " 13  mdad_2         17879 non-null  float64 \n",
      " 14  target         17879 non-null  float64 \n",
      "dtypes: category(2), float64(9), int64(4)\n",
      "memory usage: 1.8 MB\n"
     ]
    }
   ],
   "source": [
    "for c in full_features2.columns:\n",
    "    col_type = full_features2[c].dtype\n",
    "    if col_type == 'object': # or col_type == 'int64': # or col_type.name == 'category':\n",
    "        full_features2[c] = full_features2[c].astype('category')\n",
    "full_features2.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "cb45e67d",
   "metadata": {},
   "outputs": [],
   "source": [
    "fulldata, y_fulldata = full_features2[FTS_COLS]  , np.log1p(full_features2[TARGET])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "imported-million",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:42.124859Z",
     "iopub.status.busy": "2021-04-25T10:51:42.123813Z",
     "iopub.status.idle": "2021-04-25T10:51:42.127414Z",
     "shell.execute_reply": "2021-04-25T10:51:42.126872Z"
    },
    "id": "JEGiSIpDj56m",
    "papermill": {
     "duration": 0.086963,
     "end_time": "2021-04-25T10:51:42.127554",
     "exception": false,
     "start_time": "2021-04-25T10:51:42.040591",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# трансформеры\n",
    "final_cat_pipe = Pipeline([('enc',CatBoostEncoder() )])  #OneHotEncoder(handle_unknown='ignore', sparse=False))])\n",
    "final_num_pipe = Pipeline([('scal', None)]) # \n",
    "\n",
    "final_transformers = [('num', final_num_pipe, num_columns),\n",
    "                     ('cat', final_cat_pipe, cat_columns),]\n",
    "\n",
    "# передаем список трансформеров в ColumnTransformer\n",
    "final_transformer = ColumnTransformer(transformers=final_transformers)\n",
    "\n",
    "# задаем итоговый конвейер ПОКА ЧТО С НАЧАЛЬНЫМИ НАСТРОЙКАМИ\n",
    "final_ml_pipe = Pipeline([('tr', final_transformer), \n",
    "                     ('ml', xgb.XGBRegressor(**params) )])\n",
    "\n",
    "if Phase_1:\n",
    "    final_ml_pipe.set_params(**OPT_PARAMS_PIPE)\n",
    "\n",
    "\n",
    "if Phase_2 or Phase_3 or Phase_4:\n",
    "    # Для контроля изменений смотрим выбранные параметры модели \n",
    "    opt_par = ['ml__n_estimators','ml__learning_rate',\n",
    "               'ml__max_depth','ml__min_child_weight','ml__subsample']\n",
    "    print(opt_par)\n",
    "    print( 'Before modification ml_pipe3: ' ,[final_ml_pipe.get_params()[x] for x in opt_par])\n",
    "    \n",
    "    # УСТАНОВКА В НОВЫЙ PIPE НАИЛУЧШИХ ЗНАЧЕНИЙ НАЙДЕННЫХ В ПРЕДЫДУЩИХ ФАЗАХ:  \n",
    "    # присваиваем итоговому конвейеру оптимальные значения гиперпараметров найденные optuna\n",
    "    final_ml_pipe.set_params(**opt_optuna_params_pipe)\n",
    "    \n",
    "    # Для контроля изменений\n",
    "    print( 'After modification ml_pipe3: ' ,[final_ml_pipe.get_params()[x] for x in opt_par])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "square-entity",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:42.286375Z",
     "iopub.status.busy": "2021-04-25T10:51:42.285294Z",
     "iopub.status.idle": "2021-04-25T10:51:42.290200Z",
     "shell.execute_reply": "2021-04-25T10:51:42.289660Z"
    },
    "papermill": {
     "duration": 0.087365,
     "end_time": "2021-04-25T10:51:42.290336",
     "exception": false,
     "start_time": "2021-04-25T10:51:42.202971",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ml__n_estimators  :  330\n",
      "ml__learning_rate  :  0.055\n",
      "ml__max_depth  :  4\n",
      "ml__min_child_weight  :  115\n",
      "ml__colsample_bytree  :  0.7359281520613952\n",
      "ml__subsample  :  0.3350726311191104\n",
      "ml__lambda  :  0.07017450086376546\n",
      "ml__alpha  :  0.06778367298243107\n",
      "ml__gamma  :  0.30129207712879835\n"
     ]
    }
   ],
   "source": [
    "opt_par = ['ml__n_estimators','ml__learning_rate','ml__max_depth',\n",
    "           'ml__min_child_weight','ml__colsample_bytree','ml__subsample',\n",
    "           'ml__lambda','ml__alpha','ml__gamma']\n",
    "\n",
    "for n, p in zip(opt_par,[final_ml_pipe.get_params()[x] for x in opt_par]):\n",
    "    print(n, \" : \", p)"
   ]
  },
  {
   "cell_type": "raw",
   "id": "d7ad7eb7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:42.617688Z",
     "iopub.status.busy": "2021-04-25T10:51:42.616671Z",
     "iopub.status.idle": "2021-04-25T10:51:42.620462Z",
     "shell.execute_reply": "2021-04-25T10:51:42.619910Z"
    },
    "papermill": {
     "duration": 0.086094,
     "end_time": "2021-04-25T10:51:42.620632",
     "exception": false,
     "start_time": "2021-04-25T10:51:42.534538",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Нужно увеличить n_estimators, ЕСЛИ параметры были найдены на уменьшенном наборе данных\n",
    "par['ml__n_estimators'] = int(final_ml_pipe.get_params()['ml__n_estimators'] * (1 + 1/CV))\n",
    "final_ml_pipe.set_params(**par )# 'n_estimators' ml__learning_rate\n",
    "par"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "published-diving",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:43.528343Z",
     "iopub.status.busy": "2021-04-25T10:51:43.519443Z",
     "iopub.status.idle": "2021-04-25T10:51:43.531989Z",
     "shell.execute_reply": "2021-04-25T10:51:43.531478Z"
    },
    "papermill": {
     "duration": 0.101971,
     "end_time": "2021-04-25T10:51:43.532161",
     "exception": false,
     "start_time": "2021-04-25T10:51:43.430190",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "with open(NAME_RUN_LOG, 'at', encoding='utf-8') as logfile:\n",
    "        print('Параметры конечной модели, формирующей посылку(submission): \\n{}'.format(final_ml_pipe.get_params()), file=logfile)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "045e1316",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SCORE на всей исторической выборке: 2.274\n"
     ]
    }
   ],
   "source": [
    "# получаем ответы (вероятности) для проверочных блоков перекрестной проверки\n",
    "XGBM_pred = cross_val_predict(final_ml_pipe, fulldata[-941*3:], y_fulldata[-941*3:], cv=10, n_jobs=-1, method='predict') #[:,1]\n",
    "# смотрим значение rsmle\n",
    "print('SCORE на всей исторической выборке: {:.3f}'.format(\n",
    "        rmsle(y_fulldata[-941*3:], np.expm1(XGBM_pred) )))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "desirable-colombia",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T11:10:31.631687Z",
     "iopub.status.busy": "2021-04-25T11:10:31.630516Z",
     "iopub.status.idle": "2021-04-25T11:10:31.637099Z",
     "shell.execute_reply": "2021-04-25T11:10:31.637952Z"
    },
    "id": "qnHI4879j56o",
    "papermill": {
     "duration": 0.108114,
     "end_time": "2021-04-25T11:10:31.638168",
     "exception": false,
     "start_time": "2021-04-25T11:10:31.530054",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Duration: 0.0 hours 0.0 minutes 46.937235832214355 seconds.\n",
      "\n",
      "\n",
      "Время окончания работы скрипта: 17-12-2021 19:22\n",
      "***********************\n",
      "\n"
     ]
    }
   ],
   "source": [
    "end_time = time()\n",
    "time_taken = end_time - start_time # time_taken is in seconds\n",
    "hours, rest = divmod(time_taken,3600)\n",
    "minutes, seconds = divmod(rest, 60)\n",
    "print('Duration: {} hours {} minutes {} seconds.'.format(hours, minutes, seconds))\n",
    "print('\\n\\nВремя окончания работы скрипта: {}\\n***********************\\n'.format(datetime.now().strftime(\"%d-%m-%Y %H:%M\")))\n",
    "with open(NAME_RUN_LOG, 'at', encoding='utf-8') as logfile:\n",
    "    print('\\n\\nВремя окончания работы скрипта: {}\\n***********************\\n'.format(datetime.now().strftime(\"%d-%m-%Y %H:%M\")), \n",
    "          file=logfile)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "architectural-edwards",
   "metadata": {
    "papermill": {
     "duration": 0.086982,
     "end_time": "2021-04-25T11:10:32.409572",
     "exception": false,
     "start_time": "2021-04-25T11:10:32.322590",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Для использование в дальнейшем стекинге:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "alike-advertiser",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T11:10:33.641287Z",
     "iopub.status.busy": "2021-04-25T11:10:33.640214Z",
     "iopub.status.idle": "2021-04-25T11:10:34.470701Z",
     "shell.execute_reply": "2021-04-25T11:10:34.471217Z"
    },
    "papermill": {
     "duration": 0.920739,
     "end_time": "2021-04-25T11:10:34.471551",
     "exception": false,
     "start_time": "2021-04-25T11:10:33.550812",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.30203128, 4.38606739, 3.26788712, 1.57490647, 2.11707187,\n",
       "       1.41892838, 5.43208838, 5.33820248, 3.30792236, 5.54022026])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#XGBM_probs.to_csv(\"XGBM_probs_for_staking(v1)_TEST\"+'.'+d_ext)\n",
    "np.savetxt(NAME_OUTPUT_FOR_STAKING, XGBM_pred )\n",
    "# Проверим\n",
    "new_num_arr2 = np.loadtxt(NAME_OUTPUT_FOR_STAKING)\n",
    "new_num_arr2[:10]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "leading-solid",
   "metadata": {
    "papermill": {
     "duration": 0.092869,
     "end_time": "2021-04-25T11:10:32.052444",
     "exception": false,
     "start_time": "2021-04-25T11:10:31.959575",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# ### Adjusting over the entire historical sample Final phase"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "comfortable-shakespeare",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2021-04-25T10:51:43.724036Z",
     "iopub.status.busy": "2021-04-25T10:51:43.722853Z",
     "iopub.status.idle": "2021-04-25T10:52:54.365689Z",
     "shell.execute_reply": "2021-04-25T10:52:54.364505Z"
    },
    "id": "L_w96b7Sj56n",
    "papermill": {
     "duration": 70.74439,
     "end_time": "2021-04-25T10:52:54.365928",
     "exception": false,
     "start_time": "2021-04-25T10:51:43.621538",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Wall time: 2.68 s\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "Pipeline(steps=[('tr',\n",
       "                 ColumnTransformer(transformers=[('num',\n",
       "                                                  Pipeline(steps=[('scal',\n",
       "                                                                   None)]),\n",
       "                                                  ['vol_tm6', 'vol_tm5',\n",
       "                                                   'vol_tm4', 'vol_tm3',\n",
       "                                                   'vol_tm2', 'vol_tm1',\n",
       "                                                   'last_year_avg', 'mdad_2']),\n",
       "                                                 ('cat',\n",
       "                                                  Pipeline(steps=[('enc',\n",
       "                                                                   CatBoostEncoder())]),\n",
       "                                                  ['material_code',\n",
       "                                                   'company_code', 'country',\n",
       "                                                   'region', 'manager_code',\n",
       "                                                   'month'])])),\n",
       "                ('ml',\n",
       "                 XGBRegressor(alpha=0.067783672982...\n",
       "                              lambda=0.07017450086376546, learning_rate=0.055,\n",
       "                              max_delta_step=0, max_depth=4,\n",
       "                              min_child_weight=115, missing=nan,\n",
       "                              monotone_constraints='()', n_estimators=330,\n",
       "                              n_jobs=4, num_parallel_tree=1, predictor='auto',\n",
       "                              random_state=82736, reg_alpha=0.0677836761,\n",
       "                              reg_lambda=0.0701745003, scale_pos_weight=1,\n",
       "                              subsample=0.3350726311191104, tree_method='exact',\n",
       "                              validate_parameters=1, verbosity=None))])"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "%%time\n",
    "\n",
    "# обучаем обновленную модель на всей обучающей выборке\n",
    "final_ml_pipe.fit(fulldata, y_fulldata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "explicit-rating",
   "metadata": {
    "papermill": {
     "duration": 0.085876,
     "end_time": "2021-04-25T11:10:34.645302",
     "exception": false,
     "start_time": "2021-04-25T11:10:34.559426",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "dill.dump(final_ml_pipe, file = open(\"pipe_XGB_1.cbm\", \"wb\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "ffc9d2a5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Overwriting predict.py\n"
     ]
    }
   ],
   "source": [
    "%%writefile predict.py\n",
    "\n",
    "import pathlib\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "#from catboost import CatBoostRegressor\n",
    "#import lightgbm as lgb\n",
    "#import xgboost as xgb\n",
    "#from sklearn.pipeline import Pipeline\n",
    "#from sklearn.compose import ColumnTransformer\n",
    "import dill\n",
    "#from category_encoders import TargetEncoder, OrdinalEncoder, CatBoostEncoder\n",
    "\n",
    "MODEL_FILE = pathlib.Path(__file__).parent.joinpath(\"pipe_XGB_1.cbm\")\n",
    "#ENCODER_1_FILE = pathlib.Path(__file__).parent.joinpath(\"ET_encoder_1.pkl\")\n",
    "#ENCODER_2_FILE = pathlib.Path(__file__).parent.joinpath(\"ET_encoder_2.pkl\")\n",
    "\n",
    "AGG_COLS = [\"material_code\", \"company_code\", \"country\", \"region\", \"manager_code\"]\n",
    "CAT_COLS = [\"material_code\", \"company_code\", \"country\", \"region\", \"manager_code\", \"month\"]\n",
    "FTS_COLS = ['material_code', 'company_code', 'country', 'region', 'manager_code', 'month', \n",
    "            'vol_tm6', 'vol_tm5', 'vol_tm4', 'vol_tm3', 'vol_tm2', 'vol_tm1', 'last_year_avg', 'mdad_2']\n",
    "\n",
    "TARGET = \"target\"\n",
    "\n",
    "def get_features(df: pd.DataFrame, month: pd.Timestamp) -> pd.DataFrame:\n",
    "    \"\"\"Вычисление признаков для `month`.\"\"\"\n",
    "\n",
    "    start_period = month - pd.offsets.MonthBegin(6)\n",
    "    end_period = month - pd.offsets.MonthBegin(1)\n",
    "\n",
    "    df = df.loc[:, :end_period]\n",
    "\n",
    "    features = pd.DataFrame([], index=df.index)\n",
    "    features[\"month\"] = month.month\n",
    "    features[[f\"vol_tm{i}\" for i in range(6, 0, -1)]] = df.loc[:, start_period:end_period].copy()\n",
    "\n",
    "   ### !!!!!!!!!!!!!!   #################################################################################\n",
    "    rolling = df.rolling(12, axis=1, min_periods=1)\n",
    "    features = features.join(rolling.mean().iloc[:, -1].rename(\"last_year_avg\"))\n",
    "    \n",
    "    # Добавление скользящих средних абсолютные отклонения(MDAD)\n",
    "    rolling = df.rolling(2, axis=1, min_periods=1)\n",
    "    features = features.join( \n",
    "                    rolling.apply(lambda x: np.nanmedian(np.abs(x - np.nanmedian(x))) , raw=True \n",
    "                    ).iloc[:, -1].rename(\"mdad_2\") )\n",
    "    \n",
    "    return features.reset_index()\n",
    "\n",
    "\n",
    "def predict(df: pd.DataFrame, month: pd.Timestamp) -> pd.DataFrame:\n",
    "\n",
    "    model = dill.load(open(MODEL_FILE, \"rb\"))\n",
    "\n",
    "    \n",
    "    \n",
    "    group_ts = df.groupby(AGG_COLS + [\"month\"])[\"volume\"].sum().unstack(fill_value=0)\n",
    "    features = get_features(group_ts, month)\n",
    "    for c in features.columns:\n",
    "        col_type = features[c].dtype\n",
    "        if col_type == 'object': \n",
    "            features[c] = features[c].astype('category')    \n",
    "    \n",
    "    predictions = np.expm1(model.predict(features[FTS_COLS]))\n",
    "    predictions = pd.Series(predictions).clip(lower=0, upper=7000)\n",
    "\n",
    "    preds_df = features[AGG_COLS].copy()\n",
    "    preds_df[\"prediction\"] = predictions\n",
    "    return preds_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "677fcefd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<module 'predict' from 'C:\\\\Users\\\\cvirk\\\\PROJECTS\\\\Соревнования\\\\Sibur2021\\\\predict.py'>"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import predict\n",
    "import importlib\n",
    "importlib.reload(predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "b22554ab",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>month</th>\n",
       "      <th>vol_tm6</th>\n",
       "      <th>vol_tm5</th>\n",
       "      <th>vol_tm4</th>\n",
       "      <th>vol_tm3</th>\n",
       "      <th>vol_tm2</th>\n",
       "      <th>vol_tm1</th>\n",
       "      <th>last_year_avg</th>\n",
       "      <th>mdad_2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>17.0</td>\n",
       "      <td>72.0</td>\n",
       "      <td>250.0</td>\n",
       "      <td>394.0</td>\n",
       "      <td>288.0</td>\n",
       "      <td>210.0</td>\n",
       "      <td>179.833333</td>\n",
       "      <td>39.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>166.0</td>\n",
       "      <td>62.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>19.000000</td>\n",
       "      <td>31.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>22.416667</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>30.000000</td>\n",
       "      <td>25.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>936</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>7</td>\n",
       "      <td>0.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>63.0</td>\n",
       "      <td>125.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>84.0</td>\n",
       "      <td>31.416667</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>937</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>7</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.750000</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>938</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>73.0</td>\n",
       "      <td>74.0</td>\n",
       "      <td>122.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>30.0</td>\n",
       "      <td>85.583333</td>\n",
       "      <td>7.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>939</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>7</td>\n",
       "      <td>100.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>180.0</td>\n",
       "      <td>100.0</td>\n",
       "      <td>140.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>118.333333</td>\n",
       "      <td>50.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>940</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>7</td>\n",
       "      <td>40.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>40.0</td>\n",
       "      <td>20.0</td>\n",
       "      <td>21.0</td>\n",
       "      <td>25.083333</td>\n",
       "      <td>0.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 14 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     material_code  company_code     country              region  \\\n",
       "0              124          7278      Россия     Респ. Татарстан   \n",
       "1              133             0  Белоруссия        Минская обл.   \n",
       "2              133             0  Белоруссия    Могилевская обл.   \n",
       "3              133             0  Белоруссия            г. Минск   \n",
       "4              133             0   Казахстан       г. Нур-Султан   \n",
       "..             ...           ...         ...                 ...   \n",
       "936            986          9943      Россия     Смоленская обл.   \n",
       "937            998             0      Россия  Ленинградская обл.   \n",
       "938            998          3380      Россия  Ленинградская обл.   \n",
       "939            998          5410      Россия  г. Санкт-Петербург   \n",
       "940            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "     manager_code  month  vol_tm6  vol_tm5  vol_tm4  vol_tm3  vol_tm2  \\\n",
       "0           17460      7      0.0      0.0      0.0      0.0      0.0   \n",
       "1           10942      7     17.0     72.0    250.0    394.0    288.0   \n",
       "2           10942      7      0.0      0.0      0.0    166.0     62.0   \n",
       "3           10942      7      0.0      0.0      0.0     21.0      0.0   \n",
       "4           13301      7      0.0     50.0     40.0      0.0      0.0   \n",
       "..            ...    ...      ...      ...      ...      ...      ...   \n",
       "936         17460      7      0.0     21.0     63.0    125.0     84.0   \n",
       "937         18079      7      5.0      5.0      5.0      0.0      3.0   \n",
       "938         14956      7     73.0     74.0    122.0    100.0     15.0   \n",
       "939         14956      7    100.0    180.0    180.0    100.0    140.0   \n",
       "940         10737      7     40.0      0.0     20.0     40.0     20.0   \n",
       "\n",
       "     vol_tm1  last_year_avg  mdad_2  \n",
       "0        0.0       0.000000     0.0  \n",
       "1      210.0     179.833333    39.0  \n",
       "2        0.0      19.000000    31.0  \n",
       "3        0.0      22.416667     0.0  \n",
       "4       50.0      30.000000    25.0  \n",
       "..       ...            ...     ...  \n",
       "936     84.0      31.416667     0.0  \n",
       "937      3.0       4.750000     0.0  \n",
       "938     30.0      85.583333     7.5  \n",
       "939     40.0     118.333333    50.0  \n",
       "940     21.0      25.083333     0.5  \n",
       "\n",
       "[941 rows x 14 columns]"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "predict.get_features(group_ts.iloc[:, :-1], pd.Timestamp(\"2020-07-01\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "4933c853",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>material_code</th>\n",
       "      <th>company_code</th>\n",
       "      <th>country</th>\n",
       "      <th>region</th>\n",
       "      <th>manager_code</th>\n",
       "      <th>prediction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>124</td>\n",
       "      <td>7278</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Татарстан</td>\n",
       "      <td>17460</td>\n",
       "      <td>0.785872</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Минская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>113.658333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>Могилевская обл.</td>\n",
       "      <td>10942</td>\n",
       "      <td>5.807093</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Белоруссия</td>\n",
       "      <td>г. Минск</td>\n",
       "      <td>10942</td>\n",
       "      <td>3.148300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>133</td>\n",
       "      <td>0</td>\n",
       "      <td>Казахстан</td>\n",
       "      <td>г. Нур-Султан</td>\n",
       "      <td>13301</td>\n",
       "      <td>13.913647</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>936</th>\n",
       "      <td>986</td>\n",
       "      <td>9943</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Смоленская обл.</td>\n",
       "      <td>17460</td>\n",
       "      <td>49.378426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>937</th>\n",
       "      <td>998</td>\n",
       "      <td>0</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>18079</td>\n",
       "      <td>1.375150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>938</th>\n",
       "      <td>998</td>\n",
       "      <td>3380</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Ленинградская обл.</td>\n",
       "      <td>14956</td>\n",
       "      <td>26.083757</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>939</th>\n",
       "      <td>998</td>\n",
       "      <td>5410</td>\n",
       "      <td>Россия</td>\n",
       "      <td>г. Санкт-Петербург</td>\n",
       "      <td>14956</td>\n",
       "      <td>44.128330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>940</th>\n",
       "      <td>998</td>\n",
       "      <td>6346</td>\n",
       "      <td>Россия</td>\n",
       "      <td>Респ. Башкортостан</td>\n",
       "      <td>10737</td>\n",
       "      <td>11.355455</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>941 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     material_code  company_code     country              region  \\\n",
       "0              124          7278      Россия     Респ. Татарстан   \n",
       "1              133             0  Белоруссия        Минская обл.   \n",
       "2              133             0  Белоруссия    Могилевская обл.   \n",
       "3              133             0  Белоруссия            г. Минск   \n",
       "4              133             0   Казахстан       г. Нур-Султан   \n",
       "..             ...           ...         ...                 ...   \n",
       "936            986          9943      Россия     Смоленская обл.   \n",
       "937            998             0      Россия  Ленинградская обл.   \n",
       "938            998          3380      Россия  Ленинградская обл.   \n",
       "939            998          5410      Россия  г. Санкт-Петербург   \n",
       "940            998          6346      Россия  Респ. Башкортостан   \n",
       "\n",
       "     manager_code  prediction  \n",
       "0           17460    0.785872  \n",
       "1           10942  113.658333  \n",
       "2           10942    5.807093  \n",
       "3           10942    3.148300  \n",
       "4           13301   13.913647  \n",
       "..            ...         ...  \n",
       "936         17460   49.378426  \n",
       "937         18079    1.375150  \n",
       "938         14956   26.083757  \n",
       "939         14956   44.128330  \n",
       "940         10737   11.355455  \n",
       "\n",
       "[941 rows x 6 columns]"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ts_preds_tst = predict.predict(data[data.month<\"2020-07-01\"], pd.Timestamp(\"2020-07-01\"))\n",
    "ts_preds_tst "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "f15361d8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Ошибка на тестовом множестве: 1.4954\n"
     ]
    }
   ],
   "source": [
    "print(\"Ошибка на тестовом множестве:\",\n",
    "      f'{np.sqrt(mean_squared_log_error(group_ts.reset_index().iloc[:,-1], ts_preds_tst[\"prediction\"])):.4f}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "973f902b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2019-07-01 00:00:00  -> Ошибка на тестовом множестве: 1.5434\n",
      "2019-08-01 00:00:00  -> Ошибка на тестовом множестве: 1.4496\n",
      "2019-09-01 00:00:00  -> Ошибка на тестовом множестве: 1.4524\n",
      "2019-10-01 00:00:00  -> Ошибка на тестовом множестве: 1.4441\n",
      "2019-11-01 00:00:00  -> Ошибка на тестовом множестве: 1.5381\n",
      "2019-12-01 00:00:00  -> Ошибка на тестовом множестве: 1.5795\n",
      "2020-01-01 00:00:00  -> Ошибка на тестовом множестве: 1.6819\n",
      "2020-02-01 00:00:00  -> Ошибка на тестовом множестве: 1.6496\n",
      "2020-03-01 00:00:00  -> Ошибка на тестовом множестве: 1.5996\n",
      "2020-04-01 00:00:00  -> Ошибка на тестовом множестве: 1.7565\n",
      "2020-05-01 00:00:00  -> Ошибка на тестовом множестве: 1.6624\n",
      "2020-06-01 00:00:00  -> Ошибка на тестовом множестве: 1.7055\n",
      "2020-07-01 00:00:00  -> Ошибка на тестовом множестве: 1.4954\n",
      "Суммарная ошибка на тестовом множестве: 1.5814\n"
     ]
    }
   ],
   "source": [
    "ts_range = pd.date_range(\"2019-07-01\", \"2020-07-01\", freq=\"MS\")\n",
    "s_csore = 0\n",
    "for cnt, m in enumerate(ts_range):\n",
    "    #print(cnt)\n",
    "    ts_preds_ = predict.predict(data[data.month<\"2020-07-01\"], pd.Timestamp(m))\n",
    "    #print(ts_preds_[\"prediction\"])\n",
    "    #print(group_ts.reset_index().loc[:,m])\n",
    "    score = np.sqrt(mean_squared_log_error(group_ts.reset_index().loc[:,m], ts_preds_[\"prediction\"]))\n",
    "    print(m, \" -> Ошибка на тестовом множестве:\",\n",
    "      f'{score:.4f}'\n",
    "         )\n",
    "    s_csore += score\n",
    "\n",
    "print(\"Суммарная ошибка на тестовом множестве:\",\n",
    "      f'{s_csore/len(ts_range):.4f}'\n",
    "         )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "81278034",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-rwxrwxrwx 1 dimacv dimacv     55213 Dec 17 13:51 Pip_XGB_1.zip\n",
      "-rwxrwxrwx 1 dimacv dimacv     88657 Dec 17 13:57 Pip_XGB_2.zip\n",
      "-rwxrwxrwx 1 dimacv dimacv     88690 Dec 17 14:04 Pip_XGB_3.zip\n",
      "-rwxrwxrwx 1 dimacv dimacv     88690 Dec 17 14:16 Pip_XGB_4.zip\n",
      "-rwxrwxrwx 1 dimacv dimacv    123136 Dec 17 19:17 Pip_XGB_5.zip\n",
      "-rwxrwxrwx 1 dimacv dimacv    123136 Dec 17 19:23 Pip_XGB_7.zip\n"
     ]
    }
   ],
   "source": [
    "# Windows\n",
    "!tar.exe -a -c -f Pip_XGB_7.zip pipe_XGB_1.cbm requirements.txt predict.py\n",
    "!wsl ls -al | wsl grep Pip_XGB_"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 1175.250436,
   "end_time": "2021-04-25T11:10:37.128577",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2021-04-25T10:51:01.878141",
   "version": "2.3.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
